File Exchange

## Centroid Calculation Function

version 1.0 (723 Bytes) by

Calculates centroid of an object present in an image.

3.71429
14 Ratings

Updated

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.

Kai Li

### Mohammad Ali Bagheri (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);)

Anton Kylling

### Anton Kylling (view profile)

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 6.5 (R13)