mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-12 12:30:16 +08:00
MAINT: All modes in _shared.interpolation.pxd were changed to be consistent with numpy.pad naming conventions. Specifically 'nearest' was changed to 'edge' and 'mirror' was changed to 'reflect'. All functions with a mode argument that rely on these functions had their inputs changed accordingly. For now there is a deprecation warning if the user supplies mode 'nearest'. Mode 'mirror' never appeared in an official release of skimage and so has no corresponding deprecation warning.
This commit is contained in:
@@ -5,8 +5,10 @@ import numpy as np
|
||||
from scipy import spatial
|
||||
from scipy import ndimage as ndi
|
||||
|
||||
from .._shared.utils import get_bound_method_class, safe_as_int
|
||||
from .._shared.utils import (get_bound_method_class, safe_as_int,
|
||||
_mode_deprecations)
|
||||
from ..util import img_as_float
|
||||
|
||||
from ._warps_cy import _warp_fast
|
||||
|
||||
|
||||
@@ -1128,9 +1130,9 @@ def _clip_warp_output(input_image, output_image, order, mode, cval, clip):
|
||||
order : int, optional
|
||||
The order of the spline interpolation, default is 1. The order has to
|
||||
be in the range 0-5. See `skimage.transform.warp` for detail.
|
||||
mode : {'constant', 'nearest', 'reflect', 'mirror', 'wrap'}, optional
|
||||
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
|
||||
Points outside the boundaries of the input are filled according
|
||||
to the given mode.
|
||||
to the given mode. Modes match the behaviour of `numpy.pad`.
|
||||
cval : float, optional
|
||||
Used in conjunction with mode 'constant', the value outside
|
||||
the image boundaries.
|
||||
@@ -1140,7 +1142,7 @@ def _clip_warp_output(input_image, output_image, order, mode, cval, clip):
|
||||
produce values outside the given input range.
|
||||
|
||||
"""
|
||||
|
||||
mode = _mode_deprecations(mode)
|
||||
if clip and order != 0:
|
||||
min_val = input_image.min()
|
||||
max_val = input_image.max()
|
||||
@@ -1211,9 +1213,9 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
- 3: Bi-cubic
|
||||
- 4: Bi-quartic
|
||||
- 5: Bi-quintic
|
||||
mode : {'constant', 'nearest', 'reflect', 'mirror', 'wrap'}, optional
|
||||
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
|
||||
Points outside the boundaries of the input are filled according
|
||||
to the given mode.
|
||||
to the given mode. Modes match the behaviour of `numpy.pad`.
|
||||
cval : float, optional
|
||||
Used in conjunction with mode 'constant', the value outside
|
||||
the image boundaries.
|
||||
@@ -1294,7 +1296,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
>>> warped = warp(cube, coords)
|
||||
|
||||
"""
|
||||
|
||||
mode = _mode_deprecations(mode)
|
||||
image = _convert_warp_input(image, preserve_range)
|
||||
|
||||
input_shape = np.array(image.shape)
|
||||
|
||||
+23
-10
@@ -4,6 +4,18 @@ from scipy import ndimage as ndi
|
||||
from ..measure import block_reduce
|
||||
from ._geometric import (warp, SimilarityTransform, AffineTransform,
|
||||
_convert_warp_input, _clip_warp_output)
|
||||
from .._shared.utils import _mode_deprecations
|
||||
|
||||
|
||||
def _to_ndimage_mode(mode):
|
||||
""" Convert from a numpy.pad mode name to the corresponding ndimage
|
||||
mode. """
|
||||
mode = _mode_deprecations(mode.lower())
|
||||
mode_translation_dict = dict(edge='nearest', symmetric='reflect',
|
||||
reflect='mirror')
|
||||
if mode in mode_translation_dict:
|
||||
mode = mode_translation_dict[mode]
|
||||
return mode
|
||||
|
||||
|
||||
def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
@@ -35,9 +47,9 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
order : int, optional
|
||||
The order of the spline interpolation, default is 1. The order has to
|
||||
be in the range 0-5. See `skimage.transform.warp` for detail.
|
||||
mode : {'constant', 'nearest', 'reflect', 'mirror', 'wrap'}, optional
|
||||
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
|
||||
Points outside the boundaries of the input are filled according
|
||||
to the given mode.
|
||||
to the given mode. Modes match the behaviour of `numpy.pad`.
|
||||
cval : float, optional
|
||||
Used in conjunction with mode 'constant', the value outside
|
||||
the image boundaries.
|
||||
@@ -51,10 +63,10 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
|
||||
Note
|
||||
----
|
||||
Modes 'mirror' and 'reflect' are similar, but differ in whether the edge
|
||||
Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
|
||||
voxels are duplicated during the reflection. As an example, if an array
|
||||
has values [0, 1, 2] and was padded to the right by four values using
|
||||
reflect, the result would be [0, 1, 2, 2, 1, 0, 0], while for mirror it
|
||||
symmetric, the result would be [0, 1, 2, 2, 1, 0, 0], while for reflect it
|
||||
would be [0, 1, 2, 1, 0, 1, 2].
|
||||
|
||||
Examples
|
||||
@@ -76,6 +88,7 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
|
||||
# 3-dimensional interpolation
|
||||
if len(output_shape) == 3 and (image.ndim == 2
|
||||
or output_shape[2] != image.shape[2]):
|
||||
mode = _to_ndimage_mode(mode)
|
||||
dim = output_shape[2]
|
||||
if image.ndim == 2:
|
||||
image = image[:, :, np.newaxis]
|
||||
@@ -146,9 +159,9 @@ def rescale(image, scale, order=1, mode='constant', cval=0, clip=True,
|
||||
order : int, optional
|
||||
The order of the spline interpolation, default is 1. The order has to
|
||||
be in the range 0-5. See `skimage.transform.warp` for detail.
|
||||
mode : {'constant', 'nearest', 'reflect', 'mirror', 'wrap'}, optional
|
||||
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
|
||||
Points outside the boundaries of the input are filled according
|
||||
to the given mode.
|
||||
to the given mode. Modes match the behaviour of `numpy.pad`.
|
||||
cval : float, optional
|
||||
Used in conjunction with mode 'constant', the value outside
|
||||
the image boundaries.
|
||||
@@ -214,9 +227,9 @@ def rotate(image, angle, resize=False, center=None, order=1, mode='constant',
|
||||
order : int, optional
|
||||
The order of the spline interpolation, default is 1. The order has to
|
||||
be in the range 0-5. See `skimage.transform.warp` for detail.
|
||||
mode : {'constant', 'nearest', 'reflect', 'mirror', 'wrap'}, optional
|
||||
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
|
||||
Points outside the boundaries of the input are filled according
|
||||
to the given mode.
|
||||
to the given mode. Modes match the behaviour of `numpy.pad`.
|
||||
cval : float, optional
|
||||
Used in conjunction with mode 'constant', the value outside
|
||||
the image boundaries.
|
||||
@@ -368,9 +381,9 @@ def swirl(image, center=None, strength=1, radius=100, rotation=0,
|
||||
order : int, optional
|
||||
The order of the spline interpolation, default is 1. The order has to
|
||||
be in the range 0-5. See `skimage.transform.warp` for detail.
|
||||
mode : {'constant', 'nearest', 'reflect', 'mirror', 'wrap'}, optional
|
||||
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
|
||||
Points outside the boundaries of the input are filled according
|
||||
to the given mode.
|
||||
to the given mode. Modes match the behaviour of `numpy.pad`.
|
||||
cval : float, optional
|
||||
Used in conjunction with mode 'constant', the value outside
|
||||
the image boundaries.
|
||||
|
||||
@@ -70,18 +70,19 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None,
|
||||
* 1: Bi-linear (default)
|
||||
* 2: Bi-quadratic
|
||||
* 3: Bi-cubic
|
||||
mode : {'constant', 'reflect', 'mirror', 'wrap', 'nearest'}, optional
|
||||
How to handle values outside the image borders (default is constant).
|
||||
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
|
||||
Points outside the boundaries of the input are filled according
|
||||
to the given mode. Modes match the behaviour of `numpy.pad`.
|
||||
cval : string, optional (default 0)
|
||||
Used in conjunction with mode 'C' (constant), the value
|
||||
outside the image boundaries.
|
||||
|
||||
Note
|
||||
----
|
||||
Modes 'mirror' and 'reflect' are similar, but differ in whether the edge
|
||||
Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
|
||||
voxels are duplicated during the reflection. As an example, if an array
|
||||
has values [0, 1, 2] and was padded to the right by four values using
|
||||
reflect, the result would be [0, 1, 2, 2, 1, 0, 0], while for mirror it
|
||||
symmetric, the result would be [0, 1, 2, 2, 1, 0, 0], while for reflect it
|
||||
would be [0, 1, 2, 1, 0, 1, 2].
|
||||
|
||||
"""
|
||||
@@ -89,9 +90,9 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None,
|
||||
cdef double[:, ::1] img = np.ascontiguousarray(image, dtype=np.double)
|
||||
cdef double[:, ::1] M = np.ascontiguousarray(H)
|
||||
|
||||
if mode not in ('constant', 'wrap', 'reflect', 'mirror', 'nearest'):
|
||||
if mode not in ('constant', 'wrap', 'symmetric', 'reflect', 'edge'):
|
||||
raise ValueError("Invalid mode specified. Please use `constant`, "
|
||||
"`nearest`, `wrap`, `mirror` or `reflect`.")
|
||||
"`edge`, `wrap`, `reflect` or `symmetric`.")
|
||||
cdef char mode_c = ord(mode[0].upper())
|
||||
|
||||
cdef Py_ssize_t out_r, out_c
|
||||
|
||||
@@ -45,7 +45,7 @@ def pyramid_reduce(image, downscale=2, sigma=None, order=1,
|
||||
order : int, optional
|
||||
Order of splines used in interpolation of downsampling. See
|
||||
`skimage.transform.warp` for detail.
|
||||
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
|
||||
mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
|
||||
The mode parameter determines how the array borders are handled, where
|
||||
cval is the value when mode is equal to 'constant'.
|
||||
cval : float, optional
|
||||
@@ -99,7 +99,7 @@ def pyramid_expand(image, upscale=2, sigma=None, order=1,
|
||||
order : int, optional
|
||||
Order of splines used in interpolation of upsampling. See
|
||||
`skimage.transform.warp` for detail.
|
||||
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
|
||||
mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
|
||||
The mode parameter determines how the array borders are handled, where
|
||||
cval is the value when mode is equal to 'constant'.
|
||||
cval : float, optional
|
||||
@@ -164,7 +164,7 @@ def pyramid_gaussian(image, max_layer=-1, downscale=2, sigma=None, order=1,
|
||||
order : int, optional
|
||||
Order of splines used in interpolation of downsampling. See
|
||||
`skimage.transform.warp` for detail.
|
||||
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
|
||||
mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
|
||||
The mode parameter determines how the array borders are handled, where
|
||||
cval is the value when mode is equal to 'constant'.
|
||||
cval : float, optional
|
||||
@@ -245,7 +245,7 @@ def pyramid_laplacian(image, max_layer=-1, downscale=2, sigma=None, order=1,
|
||||
order : int, optional
|
||||
Order of splines used in interpolation of downsampling. See
|
||||
`skimage.transform.warp` for detail.
|
||||
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
|
||||
mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
|
||||
The mode parameter determines how the array borders are handled, where
|
||||
cval is the value when mode is equal to 'constant'.
|
||||
cval : float, optional
|
||||
|
||||
Reference in New Issue
Block a user