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 |
|---|---|---|---|
|
|
tabby_tiger_cat.jpg |
Input image file path |
|
|
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:
Kernel size:
[7, 7]specifies a 7-pixel-wide by 7-pixel-tall averaging window; larger kernels produce stronger blurring.Kernel anchor:
[-1, -1]automatically centers the anchor within the kernel, which is standard for symmetric filters.Border mode:
cvcuda.Border.REFLECT101mirrors pixels across the border without repeating the edge pixel, preventing visible seams at image boundaries.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:
Original Input Image |
Output: 7×7 Average Blur Applied |
CV-CUDA Operators Used
Operator |
Purpose |
|---|---|
Apply a box (average) blur with a rectangular kernel to smooth the image |
Common Utilities Used
read_image() - Load image as CV-CUDA tensor
write_image() - Save blurred image to disk
See Also
Resize Operator - Resize images with GPU acceleration
Common Utilities - Shared helper functions