Skip to content

Commit

Permalink
BUG Fix resize_to to return exactly requested size
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Sep 26, 2016
1 parent 188f250 commit 67e5768
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version 1.4.1+
* Fix `resize_to` return exactly the requested size
* Fix hard crash when computing texture on arrays with negative values
(issue #72)
* Added `distance` argument to haralick features (pull request #76, by
Expand Down
2 changes: 1 addition & 1 deletion mahotas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
open, \
regmin, \
regmax
from .resize import imresize
from .resize import imresize, resize_to
from .stretch import as_rgb, \
overlay, \
stretch, \
Expand Down
3 changes: 2 additions & 1 deletion mahotas/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def resize_to(im, nsize, order=3):
from .interpolate import zoom
if len(nsize) != im.ndim:
raise ValueError('mahotas.resize_to: new size does not have the same dimension as old one')
out = np.empty(nsize, dtype=im.dtype)
nsize = np.array(nsize, dtype=float)
nsize /= im.shape
return zoom(im, nsize, order=order)
return zoom(im, nsize, order=order, out=out)


def resize_rgb_to(im, nsize, order=3):
Expand Down
15 changes: 15 additions & 0 deletions mahotas/tests/test_imresize.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,18 @@ def test_resize_to():
im = im.max(2)
im = mh.resize.resize_to(im, [512,256])
assert im.shape == (512,256)

def test_resize_to():
for start,target in [
((128,128), (64,64)),
((127,128), (64,64)),
((125,128), (64,64)),
((120,128), (64,64)),
((117,128), (64,64)),
((115,128), (61,64)),
((116,129), (59,65)),
]:
assert mh.resize_to(np.zeros(start), target).shape == target
start = np.zeros((65,31))
for t0 in range(7,29):
assert mh.resize_to(start, (t0, 17)).shape == (t0, 17)

0 comments on commit 67e5768

Please sign in to comment.