Resize

Overview

The Resize sample demonstrates image resizing using CV-CUDA’s GPU-accelerated resize operator.

Usage

Basic Usage

Resize an image to 224×224 (default):

python3 resize.py -i input.jpg

Custom Dimensions

Specify target width and height:

python3 resize.py -i image.jpg -o resized.jpg --width 512 --height 512

Command-Line Arguments

Argument

Short Form

Default

Description

--input

-i

tabby_tiger_cat.jpg

Input image file path

--output

-o

cvcuda/.cache/cat_resized.jpg

Output image file path

--width

224

Target width in pixels

--height

224

Target height in pixels

Implementation

Single Image Resize

# 1. Resize the image to the specified width and height
# Since the image gets read as HWC format,
# we need to have the same number of dimensions in the output shape
# i.e. (height, width, 3)
output_image: cvcuda.Tensor = cvcuda.resize(
    input_image, (args.height, args.width, 3)
)
write_image(output_image, args.output)

# 2. If we have a batch dimension, we can still resize the image
batched_image: cvcuda.Tensor = input_image.reshape((1, *input_image.shape), "NHWC")
batched_output_image: cvcuda.Tensor = cvcuda.resize(
    batched_image, (1, args.height, args.width, 3)
)
assert batched_output_image.shape == (1, args.height, args.width, 3)

Key points:

  1. Output Shape: Must match input dimensions (H, W, C)

  2. Interpolation: Default is linear (bilinear)

  3. Aspect Ratio: Not preserved by default

Interpolation Methods

Available interpolation methods: LINEAR (default, good balance), NEAREST (fastest), CUBIC (highest quality), AREA (best for downscaling). Specify with :pydata:`cvcuda.Interp.LINEAR`, etc.

Expected Output

The output shows the image resized to the target dimensions (default 224×224):

../../_images/tabby_tiger_cat.jpg

Original Input Image

../../_images/cat_resized.jpg

Output: Resized to 224×224

CV-CUDA Operators Used

Operator

Purpose

cvcuda.resize()

Resize images to target dimensions with specified interpolation

Common Utilities Used

See Also