mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-09 07:59:40 +08:00
Rename keep_range to preserve_range, fix test cases
This commit is contained in:
@@ -995,16 +995,12 @@ def warp_coords(coord_map, shape, dtype=np.float64):
|
||||
return coords
|
||||
|
||||
|
||||
def _convert_warp_input(image, keep_range):
|
||||
def _convert_warp_input(image, preserve_range):
|
||||
"""Convert input image to double image with the appropriate range."""
|
||||
if keep_range:
|
||||
if preserve_range:
|
||||
image = image.astype(np.double)
|
||||
else:
|
||||
if image.dtype == np.double:
|
||||
image = rescale_intensity(image)
|
||||
image = np.atleast_2d(image)
|
||||
else:
|
||||
image = img_as_float(image)
|
||||
image = img_as_float(image)
|
||||
return image
|
||||
|
||||
|
||||
@@ -1027,7 +1023,7 @@ def _clip_warp_output(input_image, output_image, clip, mode, order, cval):
|
||||
|
||||
|
||||
def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
mode='constant', cval=0., clip=True, keep_range=False):
|
||||
mode='constant', cval=0., clip=True, preserve_range=False):
|
||||
"""Warp an image according to a given coordinate transformation.
|
||||
|
||||
Parameters
|
||||
@@ -1090,7 +1086,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
Whether to clip the output to the range of values of the input image.
|
||||
This is enabled by default, since higher order interpolation may
|
||||
produce values outside the given input range.
|
||||
keep_range : bool, optional
|
||||
preserve_range : bool, optional
|
||||
Whether to keep the original range of values. Otherwise, the input
|
||||
image is converted according to the conventions of `img_as_float`.
|
||||
|
||||
@@ -1159,7 +1155,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
|
||||
"""
|
||||
|
||||
image = _convert_warp_input(image, keep_range)
|
||||
image = _convert_warp_input(image, preserve_range)
|
||||
|
||||
input_shape = np.array(image.shape)
|
||||
|
||||
|
||||
+13
-13
@@ -7,7 +7,7 @@ from ._geometric import (warp, SimilarityTransform, AffineTransform,
|
||||
|
||||
|
||||
def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
keep_range=False):
|
||||
preserve_range=False):
|
||||
"""Resize image to match a certain size.
|
||||
|
||||
Performs interpolation to up-size or down-size images. For down-sampling
|
||||
@@ -45,7 +45,7 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
Whether to clip the output to the range of values of the input image.
|
||||
This is enabled by default, since higher order interpolation may
|
||||
produce values outside the given input range.
|
||||
keep_range : bool, optional
|
||||
preserve_range : bool, optional
|
||||
Whether to keep the original range of values. Otherwise, the input
|
||||
image is converted according to the conventions of `img_as_float`.
|
||||
|
||||
@@ -79,7 +79,7 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
|
||||
coord_map = np.array([map_rows, map_cols, map_dims])
|
||||
|
||||
image = _convert_warp_input(image, keep_range)
|
||||
image = _convert_warp_input(image, preserve_range)
|
||||
|
||||
out = ndimage.map_coordinates(image, coord_map, order=order,
|
||||
mode=mode, cval=cval)
|
||||
@@ -99,13 +99,13 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
tform.estimate(src_corners, dst_corners)
|
||||
|
||||
out = warp(image, tform, output_shape=output_shape, order=order,
|
||||
mode=mode, cval=cval, clip=clip, keep_range=keep_range)
|
||||
mode=mode, cval=cval, clip=clip, preserve_range=preserve_range)
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def rescale(image, scale, order=1, mode='constant', cval=0, clip=True,
|
||||
keep_range=False):
|
||||
preserve_range=False):
|
||||
"""Scale image by a certain factor.
|
||||
|
||||
Performs interpolation to upscale or down-scale images. For down-sampling
|
||||
@@ -141,7 +141,7 @@ def rescale(image, scale, order=1, mode='constant', cval=0, clip=True,
|
||||
Whether to clip the output to the range of values of the input image.
|
||||
This is enabled by default, since higher order interpolation may
|
||||
produce values outside the given input range.
|
||||
keep_range : bool, optional
|
||||
preserve_range : bool, optional
|
||||
Whether to keep the original range of values. Otherwise, the input
|
||||
image is converted according to the conventions of `img_as_float`.
|
||||
|
||||
@@ -168,11 +168,11 @@ def rescale(image, scale, order=1, mode='constant', cval=0, clip=True,
|
||||
output_shape = (rows, cols)
|
||||
|
||||
return resize(image, output_shape, order=order, mode=mode, cval=cval,
|
||||
clip=clip, keep_range=keep_range)
|
||||
clip=clip, preserve_range=preserve_range)
|
||||
|
||||
|
||||
def rotate(image, angle, resize=False, center=None, order=1, mode='constant',
|
||||
cval=0, clip=True, keep_range=False):
|
||||
cval=0, clip=True, preserve_range=False):
|
||||
"""Rotate image by a certain angle around its center.
|
||||
|
||||
Parameters
|
||||
@@ -209,7 +209,7 @@ def rotate(image, angle, resize=False, center=None, order=1, mode='constant',
|
||||
Whether to clip the output to the range of values of the input image.
|
||||
This is enabled by default, since higher order interpolation may
|
||||
produce values outside the given input range.
|
||||
keep_range : bool, optional
|
||||
preserve_range : bool, optional
|
||||
Whether to keep the original range of values. Otherwise, the input
|
||||
image is converted according to the conventions of `img_as_float`.
|
||||
|
||||
@@ -258,7 +258,7 @@ def rotate(image, angle, resize=False, center=None, order=1, mode='constant',
|
||||
tform = tform4 + tform
|
||||
|
||||
return warp(image, tform, output_shape=output_shape, order=order,
|
||||
mode=mode, cval=cval, clip=clip, keep_range=keep_range)
|
||||
mode=mode, cval=cval, clip=clip, preserve_range=preserve_range)
|
||||
|
||||
|
||||
def downscale_local_mean(image, factors, cval=0, clip=True):
|
||||
@@ -323,7 +323,7 @@ def _swirl_mapping(xy, center, rotation, strength, radius):
|
||||
|
||||
def swirl(image, center=None, strength=1, radius=100, rotation=0,
|
||||
output_shape=None, order=1, mode='constant', cval=0, clip=True,
|
||||
keep_range=False):
|
||||
preserve_range=False):
|
||||
"""Perform a swirl transformation.
|
||||
|
||||
Parameters
|
||||
@@ -363,7 +363,7 @@ def swirl(image, center=None, strength=1, radius=100, rotation=0,
|
||||
Whether to clip the output to the range of values of the input image.
|
||||
This is enabled by default, since higher order interpolation may
|
||||
produce values outside the given input range.
|
||||
keep_range : bool, optional
|
||||
preserve_range : bool, optional
|
||||
Whether to keep the original range of values. Otherwise, the input
|
||||
image is converted according to the conventions of `img_as_float`.
|
||||
|
||||
@@ -379,4 +379,4 @@ def swirl(image, center=None, strength=1, radius=100, rotation=0,
|
||||
|
||||
return warp(image, _swirl_mapping, map_args=warp_args,
|
||||
output_shape=output_shape, order=order, mode=mode, cval=cval,
|
||||
clip=clip, keep_range=keep_range)
|
||||
clip=clip, preserve_range=preserve_range)
|
||||
|
||||
@@ -269,14 +269,19 @@ def test_slow_warp_nonint_oshape():
|
||||
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)
|
||||
out = rescale(image, 2, preserve_range=False, clip=True, order=0)
|
||||
assert out.min() == 0
|
||||
assert out.max() == 2
|
||||
|
||||
out = rescale(image, 2, preserve_range=True, clip=True, order=0)
|
||||
assert out.min() == 0
|
||||
assert out.max() == 2
|
||||
|
||||
out = rescale(image.astype(np.uint8), 2, preserve_range=False,
|
||||
clip=True, order=0)
|
||||
assert out.min() == 0
|
||||
assert out.max() == 2 / 255.0
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user