[SciPy-Dev] imresize does not work with size = int

Vincent Davis vincent at vincentdavis.net
Sat Jul 3 19:29:51 EDT 2010


I might be doing something wrong but..
This is after the recent removal of the duplicate imresize
proposed fix at bottom.

>>> imresize(x, 2, mode='F')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/misc/pilutil.py",
line 313, in imresize
    imnew = im.resize(size, resample=func[interp])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.py",
line 1302, in resize
    im = self.im.resize(size, resample)
TypeError: must be 2-item sequence, not float

THIS WORKS

>>> imresize(x, 2., mode='F')
array([[-0.654, -0.654, -0.227,  0.201,  0.141,  0.081],
       [-0.654, -0.654, -0.227,  0.201,  0.141,  0.081],
       [ 0.242,  0.242, -0.254, -0.751, -0.806, -0.86 ],
       [ 1.139,  1.139, -0.282, -1.703, -1.752, -1.801],
       [ 0.216,  0.216, -0.818, -1.851, -1.591, -1.332],
       [-0.708, -0.708, -1.354, -1.999, -1.431, -0.862]], dtype=float32)

AND THIS

>>> imresize(x, (100,100), mode='F')
array([[-0.654, -0.654, -0.654, ...,  0.081,  0.081,  0.081],
       [-0.654, -0.654, -0.654, ...,  0.081,  0.081,  0.081],
       [-0.654, -0.654, -0.654, ...,  0.081,  0.081,  0.081],
       ...,
       [-0.708, -0.708, -0.708, ..., -0.862, -0.862, -0.862],
       [-0.708, -0.708, -0.708, ..., -0.862, -0.862, -0.862],
       [-0.708, -0.708, -0.708, ..., -0.862, -0.862, -0.862]], dtype=float32)

I think the problem is in line 307
size = size / 100.0
I think size needs to be a tuple
looking at line 309 which is what is used for size=float
size = (array(im.size)*size).astype(int)

I think the fix is
percent = size / 100.0
size = (array(im.size)*percent).astype(int)

Vincent



More information about the SciPy-Dev mailing list