MATLAB: How to get the coordinates of a given pixel

computer visionimage processingImage Processing Toolbox

I was wondering if there was a method to get the X,Y coordinate of a pixel in an image? I have the pixels that I'd like to get the coordinates of, but as they aren't regions, a regionprops centroid doesn't help, and I need it to be done without user input, so I can't click on them with ginput.

Best Answer

Use bilinear interpolation, like interp2() if you want the exact value of fractional coordinates. However, it may be good enough for you to do a much simpler operation of just rounding the coordinates to the nearest integer and just getting the array element
grayLevel = grayImage(round(y), round(x));
Remember, like Walter said above, it's (y,x) not (x,y) because the first index is rows and y is the row.
You might also like the impixel() function, but I don't find that any more convenient than simple indexing.