[SciPy-User] Problem with ndimage.interpolation.zoom

denis denis-bz-py@t-online...
Thu Mar 14 06:33:11 CDT 2013


Eric Emsellem <eric.emsellem <at> eso.org> writes:
 
> I have a problem with the zoom function in the ndimage module of scipy.
> I am trying to "expand/zoom" an array by a factor of e.g., 3 or 4.
> I noticed that when the input array has a shape with odd number of e.g.

Hi Eric,

1) try it with floats, as below; `zoom` uses floats internally,
then converts to (in your case) ints when done, confusing.

2) consider zoom=2 of an arange in 1d:

    0            1           2
    y0   y1   y2   y3   y4   y5

To get y0 = 0 and y5 = 2,
yj must be (5/2) * xj, *not* 2 * xj.

(For zooming by ints just np.repeat
or maybe you want a http://en.wikipedia.org/wiki/Reconstruction_filter ?)

cheers
  -- denis


    # zoom.py: print ndimage.zoom
    from __future__ import division
    import sys
    import numpy as np
    from scipy.ndimage import zoom  # $scipy/ndimage/interpolation.py

    side = 3
    exec( "\n".join( sys.argv[1:] ))  # run this.py side= ...  from sh or ipytho
    np.set_printoptions( 1, threshold=100, edgeitems=10, suppress=True )

    for dim in [1, 2]:
        shape = [side] * dim
        A = np.arange( np.prod(shape), dtype=float ).reshape(shape)
        print "in:\n", A
        print "\nzoom:\n", zoom( A, zoom=2 )
 






More information about the SciPy-User mailing list