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 |
|---|---|---|---|
|
|
tabby_tiger_cat.jpg |
Input image file path |
|
|
cvcuda/.cache/cat_resized.jpg |
Output image file path |
|
224 |
Target width in pixels |
|
|
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:
Output Shape: Must match input dimensions (H, W, C)
Interpolation: Default is linear (bilinear)
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):
Original Input Image |
Output: Resized to 224×224 |
CV-CUDA Operators Used
Operator |
Purpose |
|---|---|
Resize images to target dimensions with specified interpolation |
Common Utilities Used
read_image() - Load image as CV-CUDA tensor
write_image() - Save resized image
See Also
Hello World Sample - Uses resize in pipeline
Classification Sample - Resizes for model input
Reformat Operator - Change tensor layouts
Common Utilities - Helper functions