pyramid_expand: 0.18.3 vs 0.19.0
58 lines
@utils.channel_as_last_axis()
@utils.deprecate_multichannel_kwarg(multichannel_position=6)
def pyramid_expand(image, upscale=2, sigma=None, order=1,
def pyramid_expand(image, upscale=2, sigma=None, order=1,
mode='reflect', cval=0, multichannel=False,
mode='reflect', cval=0, multichannel=False,
preserve_range=False):
preserve_range=False, *, channel_axis=-1):
"""Upsample and then smooth image.
"""Upsample and then smooth image.
Parameters
Parameters
----------
----------
image : ndarray
image : ndarray
Input image.
Input image.
upscale : float, optional
upscale : float, optional
Upscale factor.
Upscale factor.
sigma : float, optional
sigma : float, optional
Sigma for Gaussian filter. Default is `2 * upscale / 6.0` which
Sigma for Gaussian filter. Default is `2 * upscale / 6.0` which
corresponds to a filter mask twice the size of the scale factor that
corresponds to a filter mask twice the size of the scale factor that
covers more than 99% of the Gaussian distribution.
covers more than 99% of the Gaussian distribution.
order : int, optional
order : int, optional
Order of splines used in interpolation of upsampling. See
Order of splines used in interpolation of upsampling. See
`skimage.transform.warp` for detail.
`skimage.transform.warp` for detail.
mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
The mode parameter determines how the array borders are handled, where
The mode parameter determines how the array borders are handled, where
cval is the value when mode is equal to 'constant'.
cval is the value when mode is equal to 'constant'.
cval : float, optional
cval : float, optional
Value to fill past edges of input if mode is 'constant'.
Value to fill past edges of input if mode is 'constant'.
multichannel : bool, optional
multichannel : bool, optional
Whether the last axis of the image is to be interpreted as multiple
Whether the last axis of the image is to be interpreted as multiple
channels or another spatial dimension.
channels or another spatial dimension. This argument is deprecated:
specify `channel_axis` instead.
preserve_range : bool, optional
preserve_range : bool, optional
Whether to keep the original range of values. Otherwise, the input
Whether to keep the original range of values. Otherwise, the input
image is converted according to the conventions of `img_as_float`.
image is converted according to the conventions of `img_as_float`.
Also see https://scikit-image.org/docs/dev/user_guide/data_types.html
Also see https://scikit-image.org/docs/dev/user_guide/data_types.html
channel_axis : int or None, optional
If None, the image is assumed to be a grayscale (single channel) image.
Otherwise, this parameter indicates which axis of the array corresponds
to channels.
.. versionadded:: 0.19
``channel_axis`` was added in 0.19.
Returns
Returns
-------
-------
out : array
out : array
Upsampled and smoothed float image.
Upsampled and smoothed float image.
References
References
----------
----------
.. [1] http://persci.mit.edu/pub_pdfs/pyramid83.pdf
.. [1] http://persci.mit.edu/pub_pdfs/pyramid83.pdf
"""
"""
_check_factor(upscale)
_check_factor(upscale)
multichannel = channel_axis is not None
image = convert_to_float(image, preserve_range)
image = convert_to_float(image, preserve_range)
out_shape = tuple([math.ceil(upscale * d) for d in image.shape])
out_shape = tuple([math.ceil(upscale * d) for d in image.shape])
if multichannel:
if multichannel:
out_shape = out_shape[:-1]
out_shape = out_shape[:-1]
if sigma is None:
if sigma is None:
# automatically determine sigma which covers > 99% of distribution
# automatically determine sigma which covers > 99% of distribution
sigma = 2 * upscale / 6.0
sigma = 2 * upscale / 6.0
resized = resize(image, out_shape, order=order,
resized = resize(image, out_shape, order=order,
mode=mode, cval=cval, anti_aliasing=False)
mode=mode, cval=cval, anti_aliasing=False)
out = _smooth(resized, sigma, mode, cval, multichannel)
out = _smooth(resized, sigma, mode, cval, multichannel)
return out
return out