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

Home » Public Forums » archive » Center of mess
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
Center of mess [message #35989] Mon, 04 August 2003 20:54
Thomas Launey is currently offline  Thomas Launey
Messages: 25
Registered: September 1999
Junior Member
Hello,
I am trying to calculate the centroid of a small object in an image.
The procedure that I wrote is very standard; I found the same one in
David Fannning's archive of this NG and in IDLastro. However, the result
that I get does not seem right. In the code below, the central pixel of a
5x5 image is the peak so I would expect the centroid to be at (2.5,2.5)
but the result is [2.0,2.0]. I agree that pixel "2" is the correct answer
but I would expect that the correct coordinates should be the center of
pixel "2" (I.e.: [2.5,2.5]). I am using this centroid function to refine
peak coordinates in a 2D cross-correlation so I need this 0.5 pixel
precision.
It may be just another case of a newbie getting confused by
intervals/center of bin in a distribution but some enlightment about how
IDL consider pixel coordinates would be most welcome :-)
Thomas

pro CenterOfMess ;*** calculate the center of mass of a 2D image
Array=[[1,1,1,1,1],[1,1,1,1,1],[1,1,100,1,1],$
[1,1,1,1,1],[1,1,1,1,1]]
Sizarr=size(array,/dim)
totalarr=total(array,/double)
;*** collapse the array on Y axis
Y=Total(total(array,1,/double)*(dindgen(sizarr[1])))/totalar r
;*** collapse the array on X axis
X=Total(total(array,2,/double)*(dindgen(sizarr[0])))/totalar r
;*** reserve some space above the highest peak
Zmax=max(array,min=Zmin)*1.1
window, /free, Xsize=400, Ysize=400,title="Center of mess"
loadct,12
surface, array, Zrange=[Zmin,Zmax], /lego, /save,$
Xstyle=1, Ystyle=1, Az=45, Ax=30, color=255
plots,[X,X],[Y,Y],[array[floor(X),floor(Y)],zmax],$
/T3D, thick=3, color=200
Print,"X: ",X," Y: ",Y
End


--
Thomas LAUNEY
Lab. Memory and Learning, RIKEN BSI
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: how to open file
Next Topic: IDL 6 is available on RSI ftp site

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

Current Time: Wed Oct 08 13:46:36 PDT 2025

Total time taken to generate the page: 0.00448 seconds