Center of mass in binary image
이전 댓글 표시
Hello, I have a binary image with one object. How can I calculate the center of this object, to mark it in my image and to write the coordinates in the corner of this image, like this: object: X, Y
I used this code to calculate the center of mass:
s = regionprops(bw, 'centroid');
centroids = cat(1, s.Centroid);
imshow('MY_IMAGE.jpg')
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
hold off
but how can i plot this coordinates on my image in the left corner?
Thank you for help
채택된 답변
추가 답변 (2개)
Walter Roberson
2013년 9월 18일
0 개 추천
ndgrid() of 1:width and 1:height, do a logical indexing of those according to the binary image, calculate the mean() of what is left in each of the two coordinate matrices. Result will be centre of mass along each of the two coordinates.
Mauldy Putra
2016년 12월 16일
0 개 추천
i want to ask, in your code there is bw i want to know what is bw stand for? cause i try use your code it's said "Undefined function or variable 'bw'."
thank you
댓글 수: 1
Walter Roberson
2016년 12월 16일
bw is the binary image whose center of mass is to be found.
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!