tf.keras.ops.image.resize

Resize images to size using the specified interpolation method.

image Input image or batch of images. Must be 3D or 4D.
size Size of output image in (height, width) format.
interpolation Interpolation method. Available methods are "nearest", "bilinear", and "bicubic". Defaults to "bilinear".
antialias Whether to use an antialiasing filter when downsampling an image. Defaults to False.
crop_to_aspect_ratio If True, resize the images without aspect ratio distortion. When the original aspect ratio differs from the target aspect ratio, the output image will be cropped so as to return the largest possible window in the image (of size (height, width)) that matches the target aspect ratio. By default (crop_to_aspect_ratio=False), aspect ratio may not be preserved.
pad_to_aspect_ratio If True, pad the images without aspect ratio distortion. When the original aspect ratio differs from the target aspect ratio, the output image will be evenly padded on the short side.
fill_mode When using pad_to_aspect_ratio=True, padded areas are filled according to the given mode. Only "constant" is supported at this time (fill with constant value, equal to fill_value).
fill_value Float. Padding value to use when pad_to_aspect_ratio=True.
data_format string, either "channels_last" or "channels_first". The ordering of the dimensions in the inputs. "channels_last" corresponds to inputs with shape (batch, height, width, channels) while "channels_first" corresponds to inputs with shape (batch, channels, height, weight). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "channels_last".

Resized image or batch of images.

Examples:

x = np.random.random((2, 4, 4, 3)) # batch of 2 RGB images
y = keras.ops.image.resize(x, (2, 2))
y.shape
(2, 2, 2, 3)
x = np.random.random((4, 4, 3)) # single RGB image
y = keras.ops.image.resize(x, (2, 2))
y.shape
(2, 2, 3)
x = np.random.random((2, 3, 4, 4)) # batch of 2 RGB images
y = keras.ops.image.resize(x, (2, 2),
    data_format="channels_first")
y.shape
(2, 3, 2, 2)