MATLAB: Centroid of an image

image centroid

Please, I need help with Matlab code to center the upper half of a silhouette image with respect to its horizontal centroid(ie find the centroid of an image ), after which my output will still be in an image format. Thanks in anticipation.

Best Answer

Threshold the image into black and white, and then call regionprops on the black and white image to get the centroid property.
Note: if the black part is your information and the white part is background, then call regionprops on the logical negation of your black and white image,
regionprops(~BW,'centroid') %or something similar