File Exchange

image thumbnail

Centroid Calculation Function

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


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.

Cite As

Fahd Ahmad Abbasi (2021). Centroid Calculation Function (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

steeva nur

Kai Li

the following code is easier and faster:
X=1:N; Y=1:M;

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


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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!