HQ Resize

Overview

The HQ Resize sample demonstrates high-quality image resizing using CV-CUDA’s GPU-accelerated HQ Resize operator. Unlike the standard Resize operator, HQ Resize accepts separate interpolation filters for downscaling (min_interpolation) and upscaling (mag_interpolation), and optionally applies an antialiasing low-pass filter before downscaling to eliminate moiré patterns and ringing artifacts.

Usage

Basic Usage

HQ-resize an image to 224×224 (default):

python3 hq_resize.py -i input.jpg

Custom Dimensions

Specify a target width and height with a custom output path:

python3 hq_resize.py -i input.jpg -o cat_hq_resize.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_hq_resize.jpg

Output image file path

--width

224

Target width in pixels

--height

224

Target height in pixels

Implementation

HQ Resize Operator Call

# HQ Resize uses separate interpolation filters for downscaling (min) and
# upscaling (mag), which produces sharper results than standard resize.
# LANCZOS for minification avoids moiré patterns; LINEAR for magnification
# is fast and smooth. antialias=True applies a low-pass filter before
# downscaling to further suppress aliasing.
output_image: cvcuda.Tensor = cvcuda.hq_resize(
    input_image,
    (args.height, args.width),
    min_interpolation=cvcuda.Interp.LANCZOS,
    mag_interpolation=cvcuda.Interp.LINEAR,
    antialias=True,
)
write_image(output_image, args.output)

Key points:

  1. Dual interpolation filters: min_interpolation governs downscaling and mag_interpolation governs upscaling, allowing the best filter to be chosen for each direction independently.

  2. LANCZOS for minification: The Lanczos filter provides superior sharpness and suppresses aliasing compared to LINEAR or NEAREST when reducing image size.

  3. Antialiasing flag: Setting antialias=True applies a low-pass filter before downscaling, which further reduces moiré and ringing in the output.

  4. out_size is (H, W): The target size is specified as a (height, width) tuple — no channel dimension is included; the operator infers it from the input layout.

  5. U8 in/out, no conversion: The output tensor inherits the data type and layout (HWC, uint8) of the input, so no additional type conversion is needed before saving.

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_hq_resize.jpg

Output: HQ-Resized to 224×224

CV-CUDA Operators Used

Operator

Purpose

cvcuda.hq_resize()

High-quality resize with separate min/mag interpolation filters and optional antialiasing

Common Utilities Used

See Also