tags:

views:

32

answers:

1

how to convert image pixel to image coordinate?

A: 

I assume you have an image that you have already segmented. In other words, your image is a logical array with 1's wherever the pixel is part of a feature, and 0's everywhere else (after Step 6 in this example.

If you now want to know the coordinates of all your pixels that are '1' in your image bwImage, you can use FIND.

[yCoord,xCoord] = find(bwImage);

Note how I inversed yCoord and xCoord. This is such that

figure
imshow(bwImage)
hold on
plot(xCoord,yCoord,'.')

Will plot a dot on every pixel that has the value 1.

If instead you want to merely know the centroid of each group of connected pixels, you can use REGIONPROPS.

stats = regionprops(bwImage,'Centroid');

The centroids of the groups will be stored in stats.Centroid. x and y coordinates are chosen such that plot works like above.

Jonas