mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-10 19:09:47 +08:00
Fix keep_range and add test cases
This commit is contained in:
@@ -4,8 +4,9 @@ import warnings
|
||||
import numpy as np
|
||||
from scipy import ndimage, spatial
|
||||
|
||||
from skimage._shared.utils import get_bound_method_class, safe_as_int
|
||||
from skimage.util import img_as_float
|
||||
from .._shared.utils import get_bound_method_class, safe_as_int
|
||||
from ..util import img_as_float
|
||||
from ..exposure import rescale_intensity
|
||||
from ._warps_cy import _warp_fast
|
||||
|
||||
|
||||
@@ -1148,7 +1149,10 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
if keep_range:
|
||||
image = image.astype(np.double)
|
||||
else:
|
||||
image = img_as_float(image)
|
||||
if image.dtype == np.double:
|
||||
image = rescale_intensity(image)
|
||||
else:
|
||||
image = img_as_float(image)
|
||||
|
||||
input_shape = np.array(image.shape)
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import numpy as np
|
||||
from scipy import ndimage
|
||||
|
||||
from skimage.transform._geometric import (warp, SimilarityTransform,
|
||||
AffineTransform, _clip_warp_output)
|
||||
from skimage.measure import block_reduce
|
||||
from ..util import img_as_float
|
||||
from ..exposure import rescale_intensity
|
||||
from ..measure import block_reduce
|
||||
from ._geometric import (warp, SimilarityTransform, AffineTransform,
|
||||
_clip_warp_output)
|
||||
|
||||
|
||||
def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
@@ -82,7 +84,10 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
if keep_range:
|
||||
image = image.astype(np.double)
|
||||
else:
|
||||
image = img_as_float(image)
|
||||
if image.dtype == np.double:
|
||||
image = rescale_intensity(image)
|
||||
else:
|
||||
image = img_as_float(image)
|
||||
|
||||
out = ndimage.map_coordinates(image, coord_map, order=order,
|
||||
mode=mode, cval=cval)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from numpy.testing import (assert_almost_equal, run_module_suite,
|
||||
assert_array_equal, assert_raises)
|
||||
assert_equal, assert_raises)
|
||||
import numpy as np
|
||||
from scipy.ndimage import map_coordinates
|
||||
|
||||
@@ -236,13 +236,13 @@ def test_downscale_local_mean():
|
||||
out1 = downscale_local_mean(image1, (2, 3))
|
||||
expected1 = np.array([[ 4., 7.],
|
||||
[ 16., 19.]])
|
||||
assert_array_equal(expected1, out1)
|
||||
assert_equal(expected1, out1)
|
||||
|
||||
image2 = np.arange(5 * 8).reshape(5, 8)
|
||||
out2 = downscale_local_mean(image2, (4, 5))
|
||||
expected2 = np.array([[ 14. , 10.8],
|
||||
[ 8.5, 5.7]])
|
||||
assert_array_equal(expected2, out2)
|
||||
assert_equal(expected2, out2)
|
||||
|
||||
|
||||
def test_invalid():
|
||||
@@ -255,7 +255,7 @@ def test_inverse():
|
||||
tform = SimilarityTransform(scale=0.5, rotation=0.1)
|
||||
inverse_tform = SimilarityTransform(matrix=np.linalg.inv(tform.params))
|
||||
image = np.arange(10 * 10).reshape(10, 10).astype(np.double)
|
||||
assert_array_equal(warp(image, inverse_tform), warp(image, tform.inverse))
|
||||
assert_equal(warp(image, inverse_tform), warp(image, tform.inverse))
|
||||
|
||||
|
||||
def test_slow_warp_nonint_oshape():
|
||||
@@ -267,5 +267,18 @@ def test_slow_warp_nonint_oshape():
|
||||
warp(image, lambda xy: xy, output_shape=(13.0001, 19.9999))
|
||||
|
||||
|
||||
def test_keep_range():
|
||||
image = np.linspace(0, 2, 25).reshape(5, 5)
|
||||
|
||||
out = rescale(image, 2, keep_range=False, clip=True, order=0)
|
||||
assert out.min() == 0
|
||||
assert out.max() == 1
|
||||
|
||||
out = rescale(image, 2, keep_range=True, clip=True, order=0)
|
||||
assert out.min() == 0
|
||||
assert out.max() == 2
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user