[SciPy-User] wrong output shape calculation in scipy.ndimage.interpolation.zoom

Ralf Gommers ralf.gommers@googlemail....
Tue Aug 2 08:58:48 CDT 2011


On Mon, Aug 1, 2011 at 7:47 PM, Matthieu Rigal <rigal@rapideye.de> wrote:

> Hi guys,
>
> I just detected a problem with the output shape calculation when running a
> zoom function.
> Sometimes it returns an odd value, here is an example :
> >>> import numpy
> >>> from scipy.ndimage.interpolation import zoom
> >>> aT = numpy.ones((5000,5000))
> >>> aT2 = numpy.ones((556,463))
> >>> aT3 = zoom(aT2, (float(aT.shape[0])/aT2.shape[0],
> float(aT.shape[1])/aT2.shape[1]))
> >>> aT3.shape
> (4999, 5000)
>
> Whereas adding a very little incrementation factor produces it right :
> >>> aT3 = zoom(aT2, (1.00001*float(aT.shape[0])/aT2.shape[0],
> 1.00001*float(aT.shape[1])/aT2.shape[1]))
> >>> aT3.shape
> (5000, 5000)
>
> There must be somewhere a problem with the roundings... should I file a
> ticket
> ?
>

The zoom function seems to round down when non-integer shapes are requested.
This is more a problem with the interface than an actual bug. Your first
zoom factor times the input axis size gives:

>>> (float(aT.shape[0])/aT2.shape[0]) * aT2.shape[0]
4999.9999999999991

The zoom function can't know whether you want an array of size 4999 or 5000
if you pass in a zoom factor that implies an output shape of 4999.xxx. A
patch for zoom to accept an `output_shape` keyword that would override the
`zoom` parameter may be useful.

Cheers,
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110802/9241b135/attachment.html 


More information about the SciPy-User mailing list