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
- Initialization phase
- Include the header that defines the needed functions and structures.
- Define the stream on which the algorithm will be executed, the input and output images.
- Create the output image.
- Processing phase
- 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};
- Submit the algorithm to the stream, passing the kernel, input, output images and boundary condition.
- Optionally, wait until the processing is done.
Consult the Image Convolution for a complete example.
Limitations and Constraints
Constraints for specific backends supersede the ones specified for all backends.
All Backends
- Input and output images must have the same dimensions and type.
- The following image types are accepted:
- Minimum convolution kernel size is 1x1, maximum is 11x11.
- The following boundary conditions are accepted.
PVA
- Input and output dimensions must be between 65x33 and 3264x2448.
- Minimum convolution kernel size is 2x2.
- Maximum convolution kernel size is 11x11 by default, but for image types VPI_IMAGE_TYPE_Y8 and VPI_IMAGE_TYPE_Y8I, kernel must have at most 49 elements.
- Kernel weights are restricted to \(|weight| < 1\)
- Only VPI_BOUNDARY_COND_ZERO is accepted.
Known Issues
- PVA backend implemention may return invalid results if the input kernel isn't normalized. For this reason, 2D Image Convolution sample application returns a black image when run with the PVA backend. As a workaround, try to use Separable Image Convolver for PVA if possible, or use the CUDA backend.