VPI - Vision Programming Interface

0.2.0 Release

Image Convolver

Overview

Image convolver algorithm performs a 2D convolution operation on the input image with the provided 2D kernel. This is useful when the kernel isn't separable and its dimensions are smaller than 5x5. In other cases, it's usually preferable to use the separable image convolver algorithm due to its speed.

Input Kernel Output

\[ \begin{bmatrix} 1 & 0 & -1 \\ 0 & 0 & 0 \\ -1 & 0 & 1 \end{bmatrix} \]


Implementation

Discrete 2D convolution is implemented using the following discrete function:

\[ I'[x,y] = \sum_{m=0}^{k_h} \sum_{n=0}^{k_w} K[m,n] \times I[x-(n-\lfloor k_w/2 \rfloor), y-(m-\lfloor k_h/2 \rfloor) ] \]

Where:

  • \(I\) is the input image.
  • \(I'\) is the result image.
  • \(K\) is the convolution kernel.
  • \(k_w,k_h\) are the kernel's width and height, respectively.
Note
Most computer vision libraries expect the kernel to be reversed before calling their convolution functions. Not so with VPI, we implement an actual convolution, not cross-correlation. Naturally, this is irrelevant if the kernel is symmetric.

Usage

  1. Initialization phase
    1. Include the header that defines the needed functions and structures.
    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. Define the kernel to be used. In this case, a simple 3x3 edge detector.
      float kernel[3 * 3] = {1, 0, -1, 0, 0, 0, -1, 0, 1};
    2. Submit the algorithm to the stream, passing the kernel, input, output images and boundary condition.
      vpiSubmitImageConvolver(stream, input, output, kernel, 3, 3, VPI_BOUNDARY_COND_ZERO);
    3. Optionally, wait until the processing is done.
      vpiStreamSync(stream);

Consult the Image Convolution for a complete example.

Limitations and Constraints

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

All Backends

PVA

  • Input and output dimensions must be between 65x33 and 3264x2448.
  • Minimum convolution kernel size is 2x2.
  • Maximum convolution kernel size is 11x11.
  • Kernel weights are restricted to \(|weight| < 1\)
  • Only VPI_BOUNDARY_COND_ZERO is accepted.

Performance

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

Jetson AGX Xavier
sizetypekernelCPUCUDAPVA
1920x1080u83x3 0.65 ms0.0649 ms0.9631 ms
1920x1080u85x5 1.02 ms0.0756 ms1.2312 ms
1920x1080u87x7 1.434 ms0.1192 ms1.7560 ms
1920x1080u811x11 3.622 ms0.2506 ms3.2589 ms
1920x1080u163x3 0.82 ms0.1077 ms1.0607 ms
1920x1080u165x5 1.12 ms0.1281 ms1.5125 ms
1920x1080u167x7 1.54 ms0.1923 ms2.3490 ms
1920x1080u1611x11 3.3 ms0.4171 ms4.6461 ms
Jetson TX2
sizetypekernelCPUCUDAPVA
1920x1080u83x3 1.5 ms0.256 msn/a
1920x1080u85x5 2.54 ms0.305 msn/a
1920x1080u87x7 4.07 ms0.482 msn/a
1920x1080u811x11 11.3 ms0.7997 msn/a
1920x1080u163x3 1.74 ms0.381 msn/a
1920x1080u165x5 2.83 ms0.389 msn/a
1920x1080u167x7 4.14 ms0.574 msn/a
1920x1080u1611x11 11.19 ms0.9969 msn/a
Jetson Nano
sizetypekernelCPUCUDAPVA
1920x1080u83x3 3.14 ms0.670 msn/a
1920x1080u85x5 5.73 ms0.8814 msn/a
1920x1080u87x7 8.78 ms1.3284 msn/a
1920x1080u811x11 25.55 ms2.2300 msn/a
1920x1080u163x3 3.698 ms0.964 msn/a
1920x1080u165x5 5.93 ms1.0299 msn/a
1920x1080u167x7 9.06 ms1.564 msn/a
1920x1080u1611x11 25.92 ms2.8124 msn/a
ImageConvolver.h
VPIImageType
VPIImageType
Image formats.
Definition: Types.h:190
vpiStreamSync
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
vpiSubmitImageConvolver
VPIStatus vpiSubmitImageConvolver(VPIStream stream, VPIImage input, VPIImage output, const float *kernelData, uint32_t kernelWidth, uint32_t kernelHeight, VPIBoundaryCond boundary)
Runs a generic 2D convolution over an image.
VPIImage
struct VPIImageImpl * VPIImage
Definition: Types.h:170
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.
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.
VPI_BOUNDARY_COND_ZERO
@ VPI_BOUNDARY_COND_ZERO
All pixels outside the image are considered to be zero.
Definition: Types.h:251
VPIStream
struct VPIStreamImpl * VPIStream
Definition: Types.h:164