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

Home » Public Forums » archive » Re: finding the center of gravity of an irregularly shaped roi within a 2d array
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: finding the center of gravity of an irregularly shaped roi within a 2d array [message #81253] Tue, 04 September 2012 04:35
ian.j.ashpole is currently offline  ian.j.ashpole
Messages: 5
Registered: September 2012
Junior Member
Brilliant! Thanks for your help David :-)
Ian
Re: finding the center of gravity of an irregularly shaped roi within a 2d array [message #81256 is a reply to message #81253] Mon, 03 September 2012 09:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
> ian.j.ashpole@googlemail.com writes:
>
>> If i can ask, as i am unable to find this in the code as a relative novice, how does your program actually calculate the centroid coordinates?
>
> Each pixel in the ROI is assigned a "weight" of 1, then
> a simple center-of-mass calculation is done:
>
> totalMass = Total(array)
> xcm = Total( Total(array, 2) * Indgen(arrayXSize) * scale[0] ) $
> / totalMass
> ycm = Total( Total(array, 1) * Indgen(arrayYSize) * scale[1] ) $
> / totalMass
> center = [xcm, ycm]

Sorry, I meant to include a link to additional information about
center-of-mass calculations:

http://www.idlcoyote.com/tips/centroid.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: finding the center of gravity of an irregularly shaped roi within a 2d array [message #81257 is a reply to message #81256] Mon, 03 September 2012 09:24 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ian.j.ashpole@googlemail.com writes:

> If i can ask, as i am unable to find this in the code as a relative novice, how does your program actually calculate the centroid coordinates?

Each pixel in the ROI is assigned a "weight" of 1, then
a simple center-of-mass calculation is done:

totalMass = Total(array)
xcm = Total( Total(array, 2) * Indgen(arrayXSize) * scale[0] ) $
/ totalMass
ycm = Total( Total(array, 1) * Indgen(arrayYSize) * scale[1] ) $
/ totalMass
center = [xcm, ycm]

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: finding the center of gravity of an irregularly shaped roi within a 2d array [message #81258 is a reply to message #81257] Mon, 03 September 2012 06:58 Go to previous message
ian.j.ashpole is currently offline  ian.j.ashpole
Messages: 5
Registered: September 2012
Junior Member
Ah, looks like i am :-) Thanks very much David!
If i can ask, as i am unable to find this in the code as a relative novice, how does your program actually calculate the centroid coordinates?

Cheers,
Ian
Re: finding the center of gravity of an irregularly shaped roi within a 2d array [message #81259 is a reply to message #81258] Mon, 03 September 2012 06:42 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ian writes:

> I have an array (e.g. fltarr[1133,751]) with a range of different flag values, and i want to find the center of gravity of irregularly shaped regions of interest within this array that consist of units sharing the same value. Units which make up a roi will all be connected.
>
> e.g. i=where(array eq 1,ict)
> Find center of gravity of i.
>
> I want the result to be a location that makes sense within the parent array.
>
> Is anybody able to help?

I think you are interested in "blob analysis." :-)

http://www.idlcoyote.com/ip_tips/blobanalysis.html

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL hangs on futex_wait_private
Next Topic: Re: Dash Docset for IDL 8.1

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

Current Time: Wed Oct 08 11:33:31 PDT 2025

Total time taken to generate the page: 0.00400 seconds