Re: Center of mess [message #35988 is a reply to message #35982] |
Mon, 04 August 2003 22:23  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Thomas Launey <t_launey@brain.riken.go.jp> writes:
> 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.
...
> ;*** 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
Hmm, the problem is that you are assigning pixel values with DINDGEN,
which by default will assign 0.0 to pixel 0, 1.0 to pixel 1, and so
on. You should add 0.5 to your pixel values, if you intend that the
left edge of the pixel is 0.0, the right edge is 1.0, and the center
is 0.5, etc.
Y=Total(total(array,1,/double)*(dindgen(sizarr[1]) + 0.5))/totalarr
and so on.
Good luck,
Craig
|
|
|