jax.image.resize

Contents

jax.image.resize#

jax.image.resize(image, shape, method, antialias=True, precision=Precision.HIGHEST)[source]#

Image resize.

The method argument expects one of the following resize methods:

ResizeMethod.NEAREST, "nearest"

Nearest neighbor interpolation. The values of antialias and precision are ignored.

ResizeMethod.LINEAR, "linear", "bilinear", "trilinear", "triangle"

Linear interpolation. If antialias is True, 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.CUBIC when 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_corners argument like torch.nn.functional.interpolate. That behavior can be emulated using scale_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 ResizeMethod instance 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. For ResizeMethod.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.