{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / transform / _warps / resize

function

skimage.transform._warps:resize

source: /dev/scikit-image/src/skimage/transform/_warps.py :71

Signature

def   resize ( image output_shape order = None mode = reflect cval = 0 clip = True preserve_range = False anti_aliasing = None anti_aliasing_sigma = None )

Summary

Resize image to match a certain size.

Extended Summary

Performs interpolation to up-size or down-size N-dimensional images. Note that anti-aliasing should be enabled when down-sizing images to avoid aliasing artifacts. For downsampling with an integer factor also see skimage.transform.downscale_local_mean.

Parameters

image : ndarray

Input image.

output_shape : iterable

Size of the generated output image (rows, cols[, ...][, dim]). If dim is not provided, the number of channels is preserved. In case the number of input channels does not equal the number of output channels a n-dimensional interpolation is applied.

Returns

resized : ndarray

Resized version of the input. See Notes regarding dtype.

Other Parameters

order : int, optional

The order of the spline interpolation, default is 0 if image.dtype is bool and 1 otherwise. The order has to be in the range 0-5. See skimage.transform.warp for detail.

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 : float, optional

Used in conjunction with mode 'constant', the value outside the image boundaries.

clip : bool, optional

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.

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. Also see https://scikit-image.org/docs/dev/user_guide/data_types.html

anti_aliasing : bool, optional

Whether to apply a Gaussian filter to smooth the image prior to downsampling. It is crucial to filter when downsampling the image to avoid aliasing artifacts. If not specified, it is set to True when downsampling an image whose data type is not bool. It is also set to False when using nearest neighbor interpolation (order == 0) with integer input data type.

anti_aliasing_sigma : {float, tuple of floats}, optional

Standard deviation for Gaussian filtering used when anti-aliasing. By default, this value is chosen as (s - 1) / 2 where s is the downsampling factor, where s > 1. For the up-size case, s < 1, no anti-aliasing is performed prior to rescaling.

Notes

Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge pixels 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 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].

resize uses interpolation. Unless the interpolation method is nearest-neighbor (order==0), the algorithm will generate output values as weighted averages of input values. Accordingly, the output dtype is float64 with the following exceptions:

  • When order==0, the output dtype is image.dtype.

  • When image.dtype is float16 or float32, the output dtype is float32.

For a similar function that preserves the dtype of the input, consider scipy.ndimage.zoom.

Examples

from skimage import data
from skimage.transform import resize
image = data.camera()
resize(image, (100, 100)).shape

See also

scipy.ndimage.zoom

Aliases

  • skimage.transform.resize

Referenced by