### Highlights from Centroid Calculation Function

3.71429
3.7 | 14 ratings Rate this file 21 Downloads (last 30 days) File Size: 723 Bytes File ID: #5457 Version: 1.0

# Centroid Calculation Function

### Fahd Ahmad Abbasi (view profile)

11 Jul 2004 (Updated )

Calculates centroid of an object present in an image.

File Information
Description

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.

Required Products Image Processing Toolbox
MATLAB release MATLAB 6.5 (R13)
04 May 2016 Kai Li

### Kai Li (view profile)

03 Jun 2012 Mohammad Ali Bagheri

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

Comment only
10 Mar 2010 Anton Kylling

### Anton Kylling (view profile)

Calculates the centroid of the entire image.

21 May 2008 Kameron Rausch

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

02 Apr 2008 Javeria Malik

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

18 Mar 2008 Anonimous -

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

02 Mar 2008 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

11 Dec 2007 Asma Mughal

it helped me im my Computer Vision Assignment

16 Nov 2007 Steve Jenkins
10 Mar 2007 c koley

no

08 Dec 2006 saga y
17 Nov 2006 Shirley Hui

Works well.

06 Sep 2006 Lester Chong

Simple to implement. With instructions

06 Oct 2005 shaun truong
10 Aug 2005 Carl Fischer

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