diff --git a/skimage/_shared/safe_as_int.py b/skimage/_shared/_safe_as_int.py similarity index 98% rename from skimage/_shared/safe_as_int.py rename to skimage/_shared/_safe_as_int.py index 0d665f9f..200d6efb 100644 --- a/skimage/_shared/safe_as_int.py +++ b/skimage/_shared/_safe_as_int.py @@ -3,7 +3,7 @@ import numpy as np __all__ = ['_safe_as_int'] -def _safe_as_int(val, atol=1e-7): +def safe_as_int(val, atol=1e-3): """ Attempt to safely cast values to integer format. diff --git a/skimage/_shared/utils.py b/skimage/_shared/utils.py index 9148e7ff..f94edfc5 100644 --- a/skimage/_shared/utils.py +++ b/skimage/_shared/utils.py @@ -5,8 +5,10 @@ import sys import six from ._warnings import all_warnings +from ._safe_as_int import safe_as_int -__all__ = ['deprecated', 'get_bound_method_class', 'all_warnings'] +__all__ = ['deprecated', 'get_bound_method_class', 'all_warnings', + 'safe_as_int'] class skimage_deprecation(Warning): diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 53074c00..6eb0f70a 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -4,7 +4,7 @@ import warnings import numpy as np from scipy import ndimage, spatial -from skimage._shared.utils import get_bound_method_class +from skimage._shared.utils import get_bound_method_class, safe_as_int from skimage.util import img_as_float from ._warps_cy import _warp_fast @@ -1078,7 +1078,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, if output_shape is None: output_shape = ishape else: - output_shape = np.array(output_shape, dtype=int) + output_shape = safe_as_int(output_shape) out = None diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index f85125d0..07054ab7 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -250,7 +250,11 @@ def test_inverse(): def test_slow_warp_nonint_oshape(): image = np.random.random((5, 5)) - warp(image, lambda xy: xy, output_shape=(13.1, 19.5)) + + assert_raises(ValueError, warp, image, lambda xy: xy, + output_shape=(13.1, 19.5)) + + warp(image, lambda xy: xy, output_shape=(13.0001, 19.9999)) if __name__ == "__main__":