Overview
Box Filter is a low-pass filter that smooths the image by making each output pixel the average of the surrounding ones, removing details, noise and and edges from images.
Input Window size Output
5x5
Implementation
The Box filter is implemented as a convolution operation on the input image using the following kernel:
\[ box_{m,n} = \frac{1}{mn} \begin{bmatrix} 1 & 1 & \dots & 1 \\ 1 & 1 & \dots & 1 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 1 & \dots & 1 \end{bmatrix}_{m \times n} \]
Usage
Language:
C/C++
Python
Import VPI module
Use the CUDA backend to filter input image with a 5x5 box kernel, using ZERO boundary condition. Input and output are VPI images. with vpi.Backend.CUDA:
output = input.box_filter(5, border=vpi.Border.ZERO)
Initialization phase
Include the header that defines the box filter function.
Declares functions that implement the Box Filter algorithm.
Define the input image object.
struct VPIImageImpl * VPIImage
A handle to an image.
Create the output image. It gets its dimensions and format from the input image. int32_t w, h;
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
VPIStatus vpiImageGetFormat(VPIImage img, VPIImageFormat *format)
Get the image format.
VPIStatus vpiImageGetSize(VPIImage img, int32_t *width, int32_t *height)
Get the image size in pixels.
Create the stream where the algorithm will be submitted for execution.
struct VPIStreamImpl * VPIStream
A handle to a stream.
VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
Create a stream instance.
Processing phase
Submit the algorithm to the stream along with other parameters. In this case it's a 5x5 box filter with clamp border extension. It'll be executed by the CUDA backend.
VPIStatus vpiSubmitBoxFilter(VPIStream stream, uint32_t backend, VPIImage input, VPIImage output, int32_t kernelSizeX, int32_t kernelSizeY, VPIBorderExtension border)
Runs a 2D box filter over an image.
@ VPI_BACKEND_CUDA
CUDA backend.
@ VPI_BORDER_ZERO
All pixels outside the image are considered to be zero.
Optionally, wait until the processing is done.
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
Cleanup phase
Free resources held by the stream and the input and output images.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
For more information, see Box Filter in the "API Reference" section of VPI - Vision Programming Interface .
Limitations and Constraints
Constraints for specific backends supersede the ones specified for all backends.
All Backends
Kernel size must be at least 1x1 and at most 11x11.
Accepted border extensions:
Input and output images must have same image type and size.
Accepted image formats:
PVA
Only available on Jetson Xavier devices.
Minimum kernel size is 2x2.
Accepted border extensions:
VIC
Performance
For information on how to use the performance table below, see Algorithm Performance Tables .
Before comparing measurements, consult Comparing Algorithm Elapsed Times .
For further information on how performance was benchmarked, see Performance Benchmark .
clear filters
Device:
Jetson AGX Xavier
Jetson TX2
Jetson Nano
-
Streams:
1
4
8