VPI - Vision Programming Interface

0.4.4 Release

Bilateral Filter

Overview

The Bilateral Filter is a non-linear, edge-preserving smoothing filter that is commonly used in Computer Vision as a simple noise-reduction stage in a pipeline. It calculates the intensity of each output pixel as a weighted average of intensity values from nearby pixels in the input image. Crucially, the weights depend not only on the Euclidean distance between current and neighbor pixels, but also on the radiometric differences (e.g., color intensity differences) between them. The outcome is that edges are preserved while regions with similar intensities are smoothed out.

Input Parameters Output

\begin{align*} \mathit{kernelSize} &= 7x7 \\ \sigma_s &= 1.7 \\ \sigma_r &= 50 \end{align*}

Implementation

The bilateral filter is defined as:

\[ I'(p) = \frac{1}{W_p} \sum_{q\in\Omega}I(p)k_r(\|I(q) - I(p)\|)k_s(\|p-q\|) \]

and the normalization term, W, is defined as:

\[ W_p = \sum_{q\in\Omega}k_r(\|I(p)-I(q)\|)k_s(\|p-q\|) \]

where

  • \(I\) and \(I'\) are the input and output images, respectively.
  • \(k_r\) and \(k_s\) are the range and space kernels, respectively, defined as the following non-normalized Gaussian functions:

    \begin{align*} k_r(p) &= e^{-\frac{\|p\|^2}{2\sigma_r^2}} \\ k_s(p) &= e^{-\frac{\|p\|^2}{2\sigma_s^2}} \end{align*}

  • \(\sigma_r\) controls the intensity range that is smoothed out. Higher values will lead to larger regions being smoothed out. The \(\sigma_r\) value should be selected with the dynamic range of the image pixel values in mind.
  • \(\sigma_s\) controls smoothing factor. Higher values will lead to more smoothing.

Usage

  1. Initialization phase
    1. Include the header that defines the Bilateral filter function.
    2. Define the input image.
      VPIImage input = /*...*/;
    3. Create the output image. It gets its dimensions and format from the input image.
      uint32_t w, h;
      vpiImageGetSize(input, &w, &h);
      vpiImageGetType(input, &type);
      VPIImage output;
      vpiImageCreate(w, h, type, 0, &output);
    4. Create the stream where the algorithm will be submitted for execution.
      VPIStream stream;
      vpiStreamCreate(0, &stream);
  2. Processing phase
    1. Submit the algorithm to the stream using the CUDA backend, along with all parameters. Here we're using a 7x7 kernel with \(\sigma_r=50\) and \(\sigma_s=1.7\).
    2. Optionally, wait until the processing is done.
      vpiStreamSync(stream);
  3. Cleanup phase
    1. Free resources held by the stream and the input and output images.

For more details, consult the Bilateral Filter API reference.

Limitations and Constraints

Constraints for specific backends supersede the ones specified for all backends.

All Backends

CPU

PVA and VIC

  • Not implemented.

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 Measurement.

 - 
vpiStreamCreate
VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
Create a stream instance.
BilateralFilter.h
Declares functions that implement the Bilateral Filter algorithm.
vpiStreamSync
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
VPI_BACKEND_CUDA
@ VPI_BACKEND_CUDA
CUDA backend.
Definition: Types.h:91
VPIStream
struct VPIStreamImpl * VPIStream
A handle to a stream.
Definition: Types.h:190
vpiStreamDestroy
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
vpiImageCreate
VPIStatus vpiImageCreate(uint32_t width, uint32_t height, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
vpiImageDestroy
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
vpiSubmitBilateralFilter
VPIStatus vpiSubmitBilateralFilter(VPIStream stream, VPIBackend backend, VPIImage input, VPIImage output, uint32_t kernelSize, float sigmaRange, float sigmaSpace, VPIBoundaryCond boundary)
Runs a 2D bilateral filter over an image.
VPIImage
struct VPIImageImpl * VPIImage
A handle to an image.
Definition: Types.h:196
vpiImageGetSize
VPIStatus vpiImageGetSize(VPIImage img, uint32_t *width, uint32_t *height)
Get the image size in pixels.
VPI_BOUNDARY_COND_ZERO
@ VPI_BOUNDARY_COND_ZERO
All pixels outside the image are considered to be zero.
Definition: Types.h:218
VPIImageFormat
VPIImageFormat
Pre-defined image formats.
Definition: ImageFormat.h:94
vpiImageGetType
VPIStatus vpiImageGetType(VPIImage img, VPIImageFormat *type)
Get the image format.