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

Home » Public Forums » archive » 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
IDL: Center of Gravity Function [message #8288] Thu, 20 February 1997 00:00 Go to next message
Stefan Schoene is currently offline  Stefan Schoene
Messages: 2
Registered: February 1997
Junior Member
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
Re: IDL: Center of Gravity Function [message #8334 is a reply to message #8288] Mon, 24 February 1997 00:00 Go to previous message
djackson is currently offline  djackson
Messages: 31
Registered: June 1993
Member
In article <50k9o333p2.fsf@mbcsg1.sghms.ac.uk>, Christian Soeller
<csoelle@sghms.ac.uk> wrote:

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

A fine solution, to which I might just add a memory-saver. In this case,
the rows and columns can be totaled separately, giving two 1-D arrays.
With a large starting array, this might be useful.

sz = size(array)
tot = total(array)

xcg = total(total(array,2)*indgen(sz(1)))/tot
ycg = total(total(array,1)*indgen(sz(2)))/tot

Hope this helps!

Cheers,
-Dick

Dick Jackson djackson@ibd.nrc.ca Institute for Biodiagnostics
Opinions are mine alone. National Research Council Canada, Winnipeg
"And I told him my dream was to live for all time
In some perfect refrain, like the man who wrote 'Danny Boy'."
- Joe Jackson, from the album _Night_Music_, 1994.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Slicer
Next Topic: Re: variable number of colors available on screen

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

Current Time: Wed Oct 08 13:42:29 PDT 2025

Total time taken to generate the page: 0.00432 seconds