[SciPy-User] 2D interpolation question
Zachary Pincus
zachary.pincus@yale....
Wed Mar 17 11:12:01 CDT 2010
> I'd like to do a 2D interpolation but not sure to use
> scipy.ndimage.map_coordinates or scipy.interpolate Your help is
> greatly appreciated.
>
> I have a large evenly spaced 2D array (say 8000x8000). I need to
> interpolate over a smaller-but-finer grid (say 500x500). The grid is
> an evenly spaced rectangular, but it is rotated (i.e., with an angle).
>
> Which scipy function should I call?
>
map_coordinates is likely going to be the best and simplest for tasks
like this that are basically "image resampling".
Basically, for each point in your output array, calculate the x,y
position in the input array (as floating point), and put it into the
input format described by the map_coordinates documentation (a
2x500x500 array, IIRC). Then choose the order of spline interpolation:
sound choices include 0 (nearest neighbor), 1 (linear), and 3 or 5
(higher order). The higher-order splines will give "nicer looking"
results on smooth patches, but are susceptible to ringing artifacts
near sharp edges in the input array.
The rest should be self-explanatory, but if not, ask away.
Zach
PS. if you're doing a lot of resampling of the same input array, and
speed for these operations is an absolute priority, and linear
interpolation is acceptable, you could also consider do this on the
graphics card with opengl. (I like pyglet for these tasks, but I bet
pyCUDA would work as well?) You'd just have to slice the input texture
a bit so as to not be over 4096x4096.
More information about the SciPy-User
mailing list