VPI - Vision Programming Interface

0.3.7 Release

Bilateral Image Filter

Overview

A Bilateral Image 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 image 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 Gaussian filter function.
    2. Define the stream on which the algorithm will be executed, the input and output images.
      VPIStream stream = /*...*/;
      VPIImage input = /*...*/;
    3. Create the output image.
      uint32_t w, h;
      vpiImageGetSize(input, &w, &h);
      vpiImageGetType(input, &type);
      VPIImage output;
      vpiImageCreate(w, h, type, 0, &output);
  2. Processing phase
    1. Submit the algorithm to the stream, along with all parameters. Here we're using a 7x7 kernel with \(\sigma_r=50\) and \(\sigma_s=1.7\).
      vpiSubmitBilateralImageFilter(stream, input, output, 7, 50, 1.7, VPI_BOUNDARY_COND_ZERO);
    2. Optionally, wait until the processing is done.
      vpiStreamSync(stream);

For more details, consult the API reference.

Limitations and Constraints

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

All Backends

CPU

PVA

  • Not implemented

Performance

For further information on how performance was benchmarked, see Performance Measurement.

Jetson AGX Xavier
sizetypekernelCPUCUDAPVA
1920x1080u83x3 1.47 ms0.1172 msn/a
1920x1080u85x5 3.55 ms0.2148 msn/a
1920x1080u87x7 9.9 ms0.4779 msn/a
1920x1080u811x11 24.44 ms1.4138 msn/a
1920x1080u163x3 1.70 ms0.1213 msn/a
1920x1080u165x5 4.08 ms0.2143 msn/a
1920x1080u167x7 11.5 ms0.4742 msn/a
1920x1080u1611x11 26.8 ms1.4069 msn/a
Jetson TX2
sizetypekernelCPUCUDAPVA
1920x1080u83x3 4.89 ms0.405 msn/a
1920x1080u85x5 13.7 ms0.6725 msn/a
1920x1080u87x7 34.3 ms1.317 msn/a
1920x1080u811x11 68.0 ms3.39 msn/a
1920x1080u163x3 7.38 ms0.430 msn/a
1920x1080u165x5 16.40 ms0.663 msn/a
1920x1080u167x7 38.98 ms1.2988 msn/a
1920x1080u1611x11 73.5 ms3.367 msn/a
Jetson Nano
sizetypekernelCPUCUDAPVA
1920x1080u83x3 13.576 ms1.0990 msn/a
1920x1080u85x5 34.7 ms1.8768 msn/a
1920x1080u87x7 79.9 ms3.7300 msn/a
1920x1080u811x11 180.5 ms9.734 msn/a
1920x1080u163x3 17.63 ms1.126 msn/a
1920x1080u165x5 44.7 ms1.8322 msn/a
1920x1080u167x7 86.6 ms3.6758 msn/a
1920x1080u1611x11 203.6 ms9.690 msn/a
VPIImageType
VPIImageType
Image formats.
Definition: Types.h:206
vpiSubmitBilateralImageFilter
VPIStatus vpiSubmitBilateralImageFilter(VPIStream stream, VPIImage input, VPIImage output, uint32_t kernelSize, float sigmaRange, float sigmaSpace, VPIBoundaryCond boundary)
Runs a 2D bilateral filter over an image.
vpiStreamSync
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
VPIStream
struct VPIStreamImpl * VPIStream
A handle to a stream.
Definition: Types.h:177
VPIImage
struct VPIImageImpl * VPIImage
A handle to an image.
Definition: Types.h:183
vpiImageGetSize
VPIStatus vpiImageGetSize(VPIImage img, uint32_t *width, uint32_t *height)
Get the image size in pixels.
vpiImageGetType
VPIStatus vpiImageGetType(VPIImage img, VPIImageType *type)
Get the image type.
VPI_BOUNDARY_COND_ZERO
@ VPI_BOUNDARY_COND_ZERO
All pixels outside the image are considered to be zero.
Definition: Types.h:270
vpiImageCreate
VPIStatus vpiImageCreate(uint32_t width, uint32_t height, VPIImageType type, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
BilateralImageFilter.h