File Exchange

image thumbnail

Centroid Calculation Function

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

3 Downloads

Updated 13 Jul 2004

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);)

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

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor

ait_centroid/