Finding a centroid of an area ( y coord. ) under discrete valued 2D function

12 views (last 30 days)
Hello,
I have a set of discrete pairs ( x , y ) - keys and values - 2D discrete function's samples - a histogram of input digital image that I need to process. ( y = f(x) )
I need to find y coordinate of a centroid of an area under a discrete 2D function ( histogram ) for special image processing after . I found next formulas for continues functions centroid: http://www.intmath.com/applications-integration/5-centroid-area.php
I've tried to calculate y coord. of a centroid using average method for discrete function integration but I'm not sure about computation of y , how to identify x = f-1(y) ( inverted ) and an intervals for computation in discrete case.
How to do that : from having (x,y) discrete pairs set to find the y coordinate of centroid of an area under the function y = f(x) for the given interval [a , b] ( size N )? I need pseudo code or C or Matlab code of calculation of the y:
something like ( pseudocode ):
function find_centroid ( map<Key,Value>input_hist ) returns int y;
Can anybody post a link for such problem solved , such function implemented or description of the algorithm ?
Thanks in advance

Answers (1)

Doug Hull
Doug Hull on 14 Nov 2011
I think I did something kinda similar to this in my book. The code is here.
It was for finding centroids of shapes made by compositing circles, rectangles and triangles.
  1 Comment
Pavl M.
Pavl M. on 15 Nov 2011
Hello Doug.Thank you for the answer , I've took a look at the .m files , -> yes you calculate centroid in several functions:
hortrap,rectube,tbeam,titleblock,twovector,vertrap,vertia.In next way:
xcentroid=hortrap(b,Origh,a,p,'centx');
ycentroid=hortrap(b,Origh,a,p,'centy');
xcentroid=rectube(ob,oh,ib,ih,'centx');
ycentroid=rectube(ob,oh,ib,ih,'centy');
It seems there are recoursive calls in all of the function to compute centroid. Also it seems you use there trapezoidal partition for integration. But I do not understand yet what is the algorithm for computing ycentroid from x = f(y) 2D discrete function samples ,how to find inverse y = f^-1(x) function from discrete samples there is no one to one mapping as in case of histogram , intergrational partition ? Thanks.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!