How to calculate the centroid / center of a patch?
25 views (last 30 days)
More Answers (2)
Constantino Carlos Reyes-Aldasoro on 1 Mar 2022
The data X,Y must have been previously calculated from some raw data, say a thresholded figure, it is from that data you can easily calculate centroids with regionprops
Image Analyst on 1 Mar 2022
Depends on what you have. If you have just arbitrary (x,y) data gotten somehow, like through assignment, then you can create a polyshape with the polyshape() function, and then use centroid(), like @David Hill showed.
If you have a binary image (like @Constantino Carlos Reyes-Aldasoro assumed -- say from thresholding), and want the centroid of each region, you can use regionprops():
props = regionprops(binaryImage, 'Centroid');
xyCentroids = vertcat(props.Centroid)
If you'd like a tutorial on image segmentation that shows that, you can see my Image Segmentation Tutorial: