How to calculate the centroid / center of a patch?
7 次查看(过去 30 天)
显示 更早的评论
Maybe something like this?
[Xc,Yc] = centroid(patch('XData',X,'YData',Y))
2 个评论
jessupj
2022-3-1
i have you tried polyshape instead of a patch? you're defining the patch there with x,y data, so you can use those data to define the right object to apply centroid to
采纳的回答
更多回答(2 个)
Constantino Carlos Reyes-Aldasoro
2022-3-1
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
2022-3-1
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Microscopy 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!