| Re: rebin but ignore zero [message #62675 is a reply to message #62661] |
Fri, 26 September 2008 13:15  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Klassen writes:
> I have a very sparse array (image) and I want to resize it---shrink
> it by a factor of 2 in each direction. If I do a rebin, every pixel
> is
> replaced by its nearest neighbor average, but many of those
> neighbors are zeroes---not real zeroes, but zero because there
> is no data there. This means, the resulting rebin-ed image has
> values that are smaller than they "should" be.
>
> Is there a way to do a rebin that can ignore these "blank" pixels?
In contrast to what the documentation says, REBIN insists on doing
bilinear sampling when minifying a dimension. You can overcome
this by setting the SAMPLE keyword. Then nearest-neighbor sampling
will be enforced, and your data values won't change.
IDL> a=fltarr(10,10)
IDL> a[2,2] =1
IDL> a[8,8] = 1
IDL> print, rebin(a, 5, 5)
0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.250000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.250000
IDL> print, rebin(a, 5, 5, /SAMPLE)
0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 1.00000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 1.00000
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|