File Exchange

## Centroid Calculation Function

version 1.0.0.0 (723 Bytes) by
Calculates centroid of an object present in an image.

Updated 13 Jul 2004

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.

### Cite As

Fahd Ahmad Abbasi (2020). Centroid Calculation Function (https://www.mathworks.com/matlabcentral/fileexchange/5457-centroid-calculation-function), MATLAB Central File Exchange. Retrieved .

Kai Li

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

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 Compatibility
Created with R13
Compatible with any release
##### Platform Compatibility
Windows macOS Linux