Home »
Public Forums »
archive »
Re: IDL: Center of Gravity Function
Re: IDL: Center of Gravity Function [message #8287] |
Thu, 20 February 1997 00:00 |
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
|
|
|
Current Time: Wed Oct 08 19:14:56 PDT 2025
Total time taken to generate the page: 0.00552 seconds