Average Blur

Overview

The Average Blur sample demonstrates GPU-accelerated box filtering using CV-CUDA’s averageblur operator. Each output pixel is the arithmetic mean of the pixels within a rectangular kernel, producing a smoothing (low-pass) effect that reduces noise and fine detail.

Usage

Basic Usage

Apply the default 7×7 average blur to an image:

python3 averageblur.py -i input.jpg

Custom Output Path

Specify a different output file:

python3 averageblur.py -i input.jpg -o cat_averageblur.jpg

Command-Line Arguments

Argument

Short Form

Default

Description

--input

-i

tabby_tiger_cat.jpg

Input image file path

--output

-o

cvcuda/.cache/cat_averageblur.jpg

Output image file path

Implementation

Average Blur Operator Call

# Apply a 7x7 average (box) blur to smooth the image.
# kernel_anchor=[-1, -1] places the anchor at the kernel center, which is
# the conventional choice for symmetric filters.
output_image: cvcuda.Tensor = cvcuda.averageblur(
    input_image,
    kernel_size=[7, 7],
    kernel_anchor=[-1, -1],
    border=cvcuda.Border.REFLECT101,
)
write_image(output_image, args.output)

Key points:

  1. Kernel size: [7, 7] specifies a 7-pixel-wide by 7-pixel-tall averaging window; larger kernels produce stronger blurring.

  2. Kernel anchor: [-1, -1] automatically centers the anchor within the kernel, which is standard for symmetric filters.

  3. Border mode: cvcuda.Border.REFLECT101 mirrors pixels across the border without repeating the edge pixel, preventing visible seams at image boundaries.

  4. Supported dtypes: U8, U16, S16, S32, and F32 are all supported, making the operator suitable for both display images and intermediate float feature maps.

Expected Output

The output shows the image with a 7×7 box blur applied:

../../_images/tabby_tiger_cat.jpg

Original Input Image

../../_images/cat_averageblur.jpg

Output: 7×7 Average Blur Applied

CV-CUDA Operators Used

Operator

Purpose

cvcuda.averageblur()

Apply a box (average) blur with a rectangular kernel to smooth the image

Common Utilities Used

See Also