A high-performance general-purpose compute library

Separable Convolution. More...

Functions

AFAPI array convolve (const array &col_filter, const array &row_filter, const array &signal, const convMode mode=AF_CONV_DEFAULT)
 C++ Interface for separable convolution on two dimensional signals. More...
 
AFAPI af_err af_convolve2_sep (af_array *out, const af_array col_filter, const af_array row_filter, const af_array signal, const af_conv_mode mode)
 C Interface for separable convolution on two dimensional signals. More...
 

Detailed Description

Separable Convolution.

Separable Convolution is faster equivalent of the canonical 2D convolution with an additional prerequisite that the filter/kernel can be decomposed into two separate spatial vectors. A classic example of such separable kernels is sobel operator. Given below is decomposition of vertical gradient of sobel operator.

\( \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \\ \end{bmatrix} \)

can be decomposed into two vectors shown below.

\( \begin{bmatrix} 1 \\ 2 \\ 1 \\ \end{bmatrix} \)

\( \begin{bmatrix} -1 & 0 & +1 \\ \end{bmatrix} \)

Function Documentation

◆ af_convolve2_sep()

AFAPI af_err af_convolve2_sep ( af_array out,
const af_array  col_filter,
const af_array  row_filter,
const af_array  signal,
const af_conv_mode  mode 
)

C Interface for separable convolution on two dimensional signals.

Parameters
[out]outis convolved array
[in]col_filteris filter that has to be applied along the coloumns
[in]row_filteris filter that has to be applied along the rows
[in]signalis the input array
[in]modeindicates if the convolution should be expanded or not(where output size equals input)
Returns
AF_SUCCESS if the convolution is successful, otherwise an appropriate error code is returned.
Note
Separable convolution only supports two(ONE-to-ONE and MANY-to-ONE) batch modes from the ones described in the detailed description section.

◆ convolve()

AFAPI array convolve ( const array col_filter,
const array row_filter,
const array signal,
const convMode  mode = AF_CONV_DEFAULT 
)

C++ Interface for separable convolution on two dimensional signals.

// vector<dim4> numDims;
// vector<vector<float> > in;
array signal(numDims[0], &(in[0].front()));
// signal dims = [3 4 2 1]
array cFilter(numDims[1], &(in[1].front()));
// coloumn filter dims = [2 1 1 1]
array rFilter(numDims[2], &(in[2].front()));
// row filter dims = [3 1 1 1]
array output = convolve(cFilter, rFilter, signal, AF_CONV_DEFAULT);
// output signal dims = [3 4 2 1] - same as input since 'expand = false'
// notice that the input signal is 3d array, therefore
// batch mode will be automatically activated.
// output will be 3d array with result of each 2d array convolution(with
// same filter) stacked along the 3rd dimension
A multi dimensional data container.
Definition: array.h:37
@ AF_CONV_DEFAULT
Output of the convolution is the same size as input.
Definition: defines.h:305
AFAPI array convolve(const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT, const convDomain domain=AF_CONV_AUTO)
C++ Interface for convolution any(one through three) dimensional signals.
Parameters
[in]signalis the input signal
[in]col_filteris the signal that shall be along coloumns
[in]row_filteris the signal that shall be along rows
[in]modeindicates if the convolution should be expanded or not(where output size equals input)
Returns
the convolved array
Note
The default parameter of domain, AF_CONV_AUTO, heuristically switches between frequency and spatial domain.
Separable convolution only supports two(ONE-to-ONE and MANY-to-ONE) batch modes from the ones described in the detailed description section.