jax.image.resize#
- jax.image.resize(image, shape, method, antialias=True, precision=Precision.HIGHEST)[source]#
Image resize.
The
methodargument expects one of the following resize methods:ResizeMethod.NEAREST,"nearest"Nearest neighbor interpolation. The values of
antialiasandprecisionare ignored.ResizeMethod.LINEAR,"linear","bilinear","trilinear","triangle"Linear interpolation. If
antialiasisTrue, uses a triangular filter when downsampling.ResizeMethod.CUBIC,"cubic","bicubic","tricubic"Cubic interpolation, using the Keys cubic kernel.
ResizeMethod.CUBIC_PYTORCH,"cubic-pytorch","bicubic-pytorch"Cubic interpolation, matching PyTorch’s bicubic resizing behavior. Identical to
ResizeMethod.CUBICwhen antialiasing is enabled, but uses a different kernel and enables edge padding when antialiasing is disabled.ResizeMethod.LANCZOS3,"lanczos3"Lanczos resampling, using a kernel of radius 3.
ResizeMethod.LANCZOS5,"lanczos5"Lanczos resampling, using a kernel of radius 5.
ResizeMethod.AREA,"area"Area resampling. Computes the average of all pixels that fall within the output pixel’s area. When downscaling, this acts as an anti-aliasing filter. When upscaling, it acts as a box filter, matching TensorFlow’s behavior.
This function does not support an
align_cornersargument liketorch.nn.functional.interpolate. That behavior can be emulated usingscale_and_translate().- Parameters:
image – a JAX array.
shape (core.Shape) – the output shape, as a sequence of integers with length equal to the number of dimensions of image. Note that
resize()does not distinguish spatial dimensions from batch or channel dimensions, so this includes all dimensions of the image. To represent a batch or a channel dimension, simply leave that element of the shape unchanged.method (str | ResizeMethod) – the resizing method to use; either a
ResizeMethodinstance or a string. Available methods are: LINEAR, LANCZOS3, LANCZOS5, CUBIC, CUBIC_PYTORCH.antialias (bool) – should an antialiasing filter be used when downsampling? Defaults to
True. Has no effect when upsampling.
- Returns:
The resized image. The return type may differ from the input type depending on the
method. ForResizeMethod.NEAREST, the return type is the same as the input type. For other methods, the output type will be promoted to a floating point type.