comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: IDL: Center of Gravity Function
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: IDL: Center of Gravity Function [message #8287] Thu, 20 February 1997 00:00
Christian Soeller is currently offline  Christian Soeller
Messages: 46
Registered: August 1996
Member
Stefan Schoene <stefan@fritz-haber-institut.mpg.de> writes:

>
> Hi!
>
> I need a function that returns the index of the center of a
> 2-dimensional array. But I have to consider the values of the Array.
> That means, the function has to return the Center of Gravity of the
> Array.
>
> Does anybody know of such a function?
>
> Stefan

I guess your talking about what is known as the centroid of an image in
close analogy to the center of mass of a 2D mass distribution.
I think you can get what you want with

sz = size(array) ; you should probably check that you *do* have a 2D array
xcoors = indgen(sz(1)) # replicate(1,sz(2))
ycoors = replicate(1,sz(1)) # indgen(sz(2))

xcg = total(array*xcoors)/total(array)
ycg = total(array*ycoors)/total(array)

The last two lines are just the normals formulas two get the coordinates
using IDL array expressions.

Be sure to remove any offsets in your data which will otherwise effect
the computed coordinates.

Christian

------------------------------------------------------------ --------
Christian Soeller mailto: csoelle@sghms.ac.uk
St. Georges Hospital Medical School Dept. of Pharmacology
Cranmer Terrace London SW17 0RE
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ENVI: Anyone created custom applications?
Next Topic: Running time display

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:14:56 PDT 2025

Total time taken to generate the page: 0.00552 seconds