File Exchange

image thumbnail

Centroid Calculation Function

version 1.0 (723 Bytes) by

Calculates centroid of an object present in an image.

3.71429
14 Ratings

19 Downloads

Updated

No License

Function takes a picture as an argument (suitably should contain only one object whose centroid is to be obtained) and returns the x and y coordinates of its centroid.

Comments and Ratings (15)

Kai Li

Kai Li (view profile)

the following code is easier and faster:
X_hist=sum(image,1);
Y_hist=sum(image,2);
X=1:N; Y=1:M;
centX=sum(X.*X_hist)/sum(X_hist);
centY=sum(Y'.*Y_hist)/sum(Y_hist);

Besides, you may use "meshgrid" command instead of defining x variable in your code (i.e. x=meshgrid(1:columns,1:rows);)

Calculates the centroid of the entire image.

Kameron Rausch

This is a first order centroiding algorithm but is not suitable for determining the centroids of objects when a background in present.

Javeria Malik

thanks fahad this is the first step of my project implementation
Many thanks

Anonimous -

Thanks a lot for this code. It will be very useful for me =)

islam ali

thank you for this code but if there is shadow of object in pic. can this code measure the real C.G of the object

Asma Mughal

it helped me im my Computer Vision Assignment

Steve Jenkins

c koley

no

saga y

Shirley Hui

Works well.

Lester Chong

Simple to implement. With instructions

shaun truong

Carl Fischer

quick and useful. Save yourself a few minutes of coding.

MATLAB Release
MATLAB 6.5 (R13)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today

ait_centroid/