Skip to content

Loading…

Fix "imresize does not work with size = int" #3357

Merged
merged 1 commit into from

4 participants

@coveralls

Coverage Status

Coverage remained the same when pulling 855ff1f on nh2:fix-imresize-int into 32cd96d on scipy:master.

@rgommers rgommers added this to the 0.14.0 milestone
@rgommers rgommers merged commit 13c7898 into scipy:master

1 check passed

Details default The Travis CI build passed
@rgommers
SciPy member

Thanks @nh2, looks good.

@rgommers
SciPy member

The result is kind of odd (resizing is not symmetric with respect to the image), but that's a PIL issue not a scipy one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 19, 2014
  1. @nh2
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +2 −1 scipy/misc/pilutil.py
  2. +15 −0 scipy/misc/tests/test_pilutil.py
View
3 scipy/misc/pilutil.py
@@ -411,7 +411,8 @@ def imresize(arr, size, interp='bilinear', mode=None):
im = toimage(arr, mode=mode)
ts = type(size)
if issubdtype(ts,int):
- size = size / 100.0
+ percent = size / 100.0
+ size = (array(im.size)*percent).astype(int)
elif issubdtype(type(size),float):
size = (array(im.size)*size).astype(int)
else:
View
15 scipy/misc/tests/test_pilutil.py
@@ -40,6 +40,21 @@ def test_imresize3(self):
im2 = misc.imresize(im, (30,60), interp='nearest')
assert_equal(im2.shape, (30,60))
+ def test_imresize4(self):
+ im = np.array([[1,2],
+ [3,4]])
+ res = np.array([[ 1. , 1. , 1.5, 2. ],
+ [ 1. , 1. , 1.5, 2. ],
+ [ 2. , 2. , 2.5, 3. ],
+ [ 3. , 3. , 3.5, 4. ]], dtype=np.float32)
+ # Check that resizing by target size, float and int are the same
+ im2 = misc.imresize(im, (4,4), mode='F') # output size
+ im3 = misc.imresize(im, 2., mode='F') # fraction
+ im4 = misc.imresize(im, 200, mode='F') # percentage
+ assert_equal(im2, res)
+ assert_equal(im3, res)
+ assert_equal(im4, res)
+
def test_bytescale(self):
x = np.array([0,1,2], np.uint8)
y = np.array([0,1,2])
Something went wrong with that request. Please try again.