[SciPy-Dev] imresize does not work with size = int
Vincent Davis
vincent at vincentdavis.net
Sat Jul 3 19:59:48 EDT 2010
On Sat, Jul 3, 2010 at 5:29 PM, Vincent Davis <vincent at vincentdavis.net> wrote:
> 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)
Applying that change seems to fix it. The following two operation
should get the same results and do.
>>> imresize(x, 200, mode = 'F')
array([[ 0.68348145, 0.68348145, 1.43379724, 2.18411303, 1.42521787,
0.66632271],
[ 0.68348145, 0.68348145, 1.43379724, 2.18411303, 1.42521787,
0.66632271],
[-0.41771227, -0.41771227, -0.07694912, 0.26381403, 0.07136334,
-0.12108734],
[-1.518906 , -1.518906 , -1.58769548, -1.65648496, -1.28249121,
-0.90849739],
[-0.43312848, -0.43312848, -0.3485043 , -0.26388013, -0.3611995 ,
-0.45851886],
[ 0.65264904, 0.65264904, 0.89068687, 1.12872469, 0.56009215,
-0.00854035]], dtype=float32)
>>> imresize(x, 2., mode = 'F')
array([[ 0.68348145, 0.68348145, 1.43379724, 2.18411303, 1.42521787,
0.66632271],
[ 0.68348145, 0.68348145, 1.43379724, 2.18411303, 1.42521787,
0.66632271],
[-0.41771227, -0.41771227, -0.07694912, 0.26381403, 0.07136334,
-0.12108734],
[-1.518906 , -1.518906 , -1.58769548, -1.65648496, -1.28249121,
-0.90849739],
[-0.43312848, -0.43312848, -0.3485043 , -0.26388013, -0.3611995 ,
-0.45851886],
[ 0.65264904, 0.65264904, 0.89068687, 1.12872469, 0.56009215,
-0.00854035]], dtype=float32)
>
> Vincent
>
More information about the SciPy-Dev
mailing list