Re: 3D congrid without interpolation [message #53405] |
Sat, 14 April 2007 10:59  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
JD Smith wrote:
> On Thu, 12 Apr 2007 15:40:07 -0700, mgalloy@gmail.com wrote:
>
>> On Apr 12, 3:19 pm, David Fanning <n...@dfanning.com> wrote:
>>> Humm. Hard for me to imagine what you are using to
>>> do this that is interpolating anything for you.
>>> CONGRID is normally used, but that won't interpolate
>>> unless you explicitly tell it to.
>>
>> CONGRID interpolates 3-dimensional arrays by default. From the online
>> help for the INTERP keyword for CONGRID:
>>
>> INTERP
>> Set this keyword to force CONGRID to use linear interpolation when
>> resizing a 1- or 2-dimensional array. CONGRID automatically uses
>> linear interpolation if the input array is 3-dimensional. When the
>> input array is 1- or 2-dimensional, the default is to employ nearest-
>> neighbor sampling.
>
> How is "nearest neighbor sampling" not interpolation? Does it
> explicitly avoid knowledge of how the new array cell is positioned
> w.r.t. the old one, and simply grab averages of nearby neighbors? ...
No. It grabs the value of the one nearest neighbor, with appropriate
rules for breaking ties. No averaging of any kind is done on that
value, which is why it's inappropriate to call this 'interpolation'.
> ... Why
> would this ever be preferable to a linear interpolation?
Well, for one thing, it's a lot faster.
However, another good reason is if you're re-binning categorical
data, where the codes representing each category are arbitrary, and
it's simply not meaningful to take the average of the category codes.
If category 1 means 'corn' and category 3 means 'wheat', you don't
want a thin barrier line of category 2 (meaning 'barley') to ocurr at
the boundaries between wheat fields and corn fields. when you rebin
your data. Nearest neighbor interpolation will always generate either
1 or 3 along that boundary.
A third case that I'm very familiar with is mainly of use for
debugging purposes. I'm responsible for programs which calibrate and
geolocate satellite images. Occasionally I want to create a plot with
a resolution much higher than the resolution of our images, using
nearest negghbor interpolation. For any given low-resolution pixel,
there's multiple high-resolution pixels for which it is the nearest
neighbor, and they all get assigned the same color. As a result, I can
very clearly where the boundaries are between the low-resolution
pixels. That helps me decide whether or not we've geolocated those
pixels correctly.
|
|
|
Re: 3D congrid without interpolation [message #53409 is a reply to message #53405] |
Fri, 13 April 2007 18:00   |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Fri, 13 Apr 2007 17:33:53 -0700, David Fanning wrote:
> JD Smith writes:
>
>> How is "nearest neighbor sampling" not interpolation? Does it
>> explicitly avoid knowledge of how the new array cell is positioned
>> w.r.t. the old one, and simply grab averages of nearby neighbors? Why
>> would this ever be preferable to a linear interpolation?
>
> I don't know. I guess it is preferable because it
> doesn't add new numbers to your data. (I never really
> thought about or cared how it was done, but I suppose
> someone ought to.)
Aha, well I guess it really does just pick the nearest neighboring cell,
so it is not interpolation (I presumed it was averaging over neighbors
without weighting).
IDL> a=findgen(5,5)
IDL> print,a
0.00000 1.00000 2.00000 3.00000 4.00000
5.00000 6.00000 7.00000 8.00000 9.00000
10.0000 11.0000 12.0000 13.0000 14.0000
15.0000 16.0000 17.0000 18.0000 19.0000
20.0000 21.0000 22.0000 23.0000 24.0000
IDL> print,congrid(a,4,4)
0.00000 1.00000 2.00000 3.00000
5.00000 6.00000 7.00000 8.00000
10.0000 11.0000 12.0000 13.0000
15.0000 16.0000 17.0000 18.0000
IDL> print,congrid(a,4,4,/INTERP)
0.00000 1.25000 2.50000 3.75000
6.25000 7.50000 8.75000 10.0000
12.5000 13.7500 15.0000 16.2500
18.7500 20.0000 21.2500 22.5000
JD
|
|
|
|
Re: 3D congrid without interpolation [message #53411 is a reply to message #53410] |
Fri, 13 April 2007 15:57   |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Thu, 12 Apr 2007 15:40:07 -0700, mgalloy@gmail.com wrote:
> On Apr 12, 3:19 pm, David Fanning <n...@dfanning.com> wrote:
>> Humm. Hard for me to imagine what you are using to
>> do this that is interpolating anything for you.
>> CONGRID is normally used, but that won't interpolate
>> unless you explicitly tell it to.
>
> CONGRID interpolates 3-dimensional arrays by default. From the online
> help for the INTERP keyword for CONGRID:
>
> INTERP
> Set this keyword to force CONGRID to use linear interpolation when
> resizing a 1- or 2-dimensional array. CONGRID automatically uses
> linear interpolation if the input array is 3-dimensional. When the
> input array is 1- or 2-dimensional, the default is to employ nearest-
> neighbor sampling.
How is "nearest neighbor sampling" not interpolation? Does it
explicitly avoid knowledge of how the new array cell is positioned
w.r.t. the old one, and simply grab averages of nearby neighbors? Why
would this ever be preferable to a linear interpolation?
BTW, there has be a good deal of progress on interpolators, especially
for image data, which IDL hasn't taken advantage of. For example,
when downsizing, you need to take care to avoid moire artifacts and
aliasing.
Here's a classic comparison of various interpolators:
http://www.all-in-one.ee/~dersch/interpolator/interpolator.h tml
JD
|
|
|
Re: 3D congrid without interpolation [message #53425 is a reply to message #53411] |
Fri, 13 April 2007 08:21   |
Mike[2]
Messages: 99 Registered: December 2005
|
Member |
|
|
On Apr 12, 6:40 pm, "mgal...@gmail.com" <mgal...@gmail.com> wrote:
> CONGRID interpolates 3-dimensional arrays by default.
If you are really looking for a method that requires no interpolation,
you will have to choose your new array to overlap a subset of the
array indexes of the original data. I suspect you might really be
thinking about nearest neighbor interpolation. If so, you can do that
by
1 - calculating the [x,y,z] coordinates at which I want to evaluate my
data.
2 - round the coordinates
3 - interpolate a new array with interpolate(data,x,y,z)
This can be a memory hog for large arrays since you need 4 arrays for
each point in the new array. In the case where this leads to lots of
swapping, I usually do it slice by slice.
Mike
|
|
|
|
|
|
|
|
Re: 3D congrid without interpolation [message #53728 is a reply to message #53405] |
Mon, 23 April 2007 09:53  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Sat, 14 Apr 2007 10:59:26 -0700, kuyper wrote:
> JD Smith wrote:
>> On Thu, 12 Apr 2007 15:40:07 -0700, mgalloy@gmail.com wrote:
>>
>>> On Apr 12, 3:19 pm, David Fanning <n...@dfanning.com> wrote:
>>>> Humm. Hard for me to imagine what you are using to
>>>> do this that is interpolating anything for you.
>>>> CONGRID is normally used, but that won't interpolate
>>>> unless you explicitly tell it to.
>>>
>>> CONGRID interpolates 3-dimensional arrays by default. From the online
>>> help for the INTERP keyword for CONGRID:
>>>
>>> INTERP
>>> Set this keyword to force CONGRID to use linear interpolation when
>>> resizing a 1- or 2-dimensional array. CONGRID automatically uses
>>> linear interpolation if the input array is 3-dimensional. When the
>>> input array is 1- or 2-dimensional, the default is to employ nearest-
>>> neighbor sampling.
>>
>> How is "nearest neighbor sampling" not interpolation? Does it
>> explicitly avoid knowledge of how the new array cell is positioned
>> w.r.t. the old one, and simply grab averages of nearby neighbors? ...
>
> No. It grabs the value of the one nearest neighbor, with appropriate
> rules for breaking ties. No averaging of any kind is done on that
> value, which is why it's inappropriate to call this 'interpolation'.
Right, David corrected me. I guess my brain was registering "nearest
neighbor interpolation" with some weighted averaging.
>> ... Why
>> would this ever be preferable to a linear interpolation?
>
> Well, for one thing, it's a lot faster.
>
> However, another good reason is if you're re-binning categorical
> data, where the codes representing each category are arbitrary, and
> it's simply not meaningful to take the average of the category codes.
> If category 1 means 'corn' and category 3 means 'wheat', you don't
> want a thin barrier line of category 2 (meaning 'barley') to ocurr at
> the boundaries between wheat fields and corn fields. when you rebin
> your data. Nearest neighbor interpolation will always generate either
> 1 or 3 along that boundary.
Good example.
Thanks,
JD
|
|
|