hi every body, i have an image which has a picture of a ball in it and i want to find the centroid of that ball so when i display it on a 2dplot i know the exact pixel coord and then i can find it's real coord. the problem is i don't know how how to find or the formula for centroid of an object? thanks for any help, Lucas 

how to find centroid of an object in an image???
Started by ●May 23, 2003
Posted by ●May 23, 2003
Are you working with binary images. If so, then the following code will
help you find the centroid of the image:
% read the image
i = imread('ball.bmp');
% convert to double
i = double(i);
% invert the image so that we can label the image
% the invert function is not given in the DIP toolbox
% i am attaching it with this email
i = invert(i);
% apply 8connected algo
[labels,count] = bwlabel(i,8);
% calculate features. For more type help imfeature
features = imfeature(labels,'Centroid');
i = 1;
while i <= count
% display centroid of all the
subimages in the image
disp(features.Centroid);
i = i + 1;
end
Hope this helps.
Good luck Zahra Atiq Shah It's Samaritans' Week. Help Samaritans help others. Call 08709 000032 to give or donate online now at http://www.samaritans.org/support/donations.shtm  
 

Posted by ●May 23, 2003
Are you working with binary images. If so, then the following code will
help you find the centroid of the image:
% read the image
i = imread('ball.bmp');
% convert to double
i = double(i);
% invert the image so that we can label the image
% the invert function is not given in the DIP toolbox
% i am attaching it with this email
i = invert(i);
% apply 8connected algo
[labels,count] = bwlabel(i,8);
% calculate features. For more type help imfeature
features = imfeature(labels,'Centroid');
i = 1;
while i <= count
% display centroid of all the
subimages in the image
disp(features.Centroid);
i = i + 1;
end
Hope this helps.
Good luck Zahra Atiq Shah It's Samaritans' Week. Help Samaritans help others. Call 08709 000032 to give or donate online now at http://www.samaritans.org/support/donations.shtm  
 

Posted by ●May 23, 2003
hi every body, i have an image which has a picture of a ball in it and i want to find the centroid of that ball so when i display it on a 2dplot i know the exact pixel coord and then i can find it's real coord. the problem is i don't know how how to find or the formula for centroid of an object? thanks for any help, Lucas 
