Find centroid of binary image
65 次查看(过去 30 天)
显示 更早的评论
I want to know find centroid area in picture output show X,Y axis
Sample
centroid x 60 centroid y 40
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160235/image.jpeg)
0 个评论
回答(2 个)
Guillaume
2017-1-29
stats = regionprops(yourimage);
centroid = stats.centroid;
Or calculate it yourself according to its definition, the mean of the pixel coordinates:
[y, x] = ndgrid(1:size(yourimage, 1), 1:size(yourimage, 2));
centroid = mean([x(logical(yourimage)), y(logical(yourimage))]);
12 个评论
Bradley Rogers
2024-5-19
Got codegeneration and tried to make a C++ file, Centroid cant be converted over?
DGM
2024-5-20
I'm going to have to tap out once it comes to code generation stuff. I'm not familiar with what will build. I haven't really touched it, and I'm running old enough stuff that it would be moot even if I had.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!