C++ interface for Convolution. More...

array convolve (const array &f1, const array &f2, const array &signal, bool expand=false)
 Separable convolution (2D) with device arrays. More...
 
template<typename ty >
array convolve (unsigned n1, const ty *h_f1, unsigned n2, const ty *h_f2, const array &signal, bool expand=false)
 Separable convolution (2D) with host arrays. More...
 
array convolve (const array &signal, const array &filter, bool expand=false)
 Convolution (1D,2D,3D). More...
 
template<typename ty >
array convolve (const array &signal, unsigned ndims, unsigned *dims, const ty *h_kernel, bool expand=false)
 Convolution (1D,2D,3D) with host filter. More...
 

Detailed Description

C++ interface for Convolution.

A convolution is a common operation between a source array, a, and a filter (or kernel) array b. The answer to the convolution is the same as computing the coefficients in polynomial multiplication, if a and b are the coefficients.

Another way to think about it is that the filter kernel is centered on each pixel in a, and the output for that pixel or data point is the sum of the products.

Consider the following example with the calculation for the first few points shown as a comment:

array a = seq(1, 8);
//a = 1.0000
// 2.0000
// 3.0000
// 4.0000
// 5.0000
// 6.0000
// 7.0000
// 8.0000
array b = seq(0, 2);
b = pow2(b);
//b = 1.0000
// 2.0000
// 4.0000
array out = convolve(a,b);
//out = 4.0000 (0*4)+(1*2)+(2*1)
// 11.0000 (1*4)+(2*2)+(3*1)
// 18.0000 (2*4)+(3*2)+(4*1)
// 25.0000 ...
// 32.0000
// 39.0000
// 46.0000
// 44.0000

Note that pixels that are outside an image or data points that are outside the domain of a signal are treated as zero.

Function Documentation

array af::convolve ( const array &  f1,
const array &  f2,
const array &  signal,
bool  expand = false 
)

Separable convolution (2D) with device arrays.

Parameters
[in]f1filter along the columns (first dimension)
[in]f2filter along the rows (second dimension)
[in]signal
[in]expandPerforms expanded convolution if true. Default is false
Examples:
examples/getting_started/convolve.cpp, examples/image_processing/image_demo.cpp, examples/image_processing/optical_flow.cpp, and examples/pde/swe.cpp.
array af::convolve ( unsigned  n1,
const ty *  h_f1,
unsigned  n2,
const ty *  h_f2,
const array &  signal,
bool  expand = false 
)

Separable convolution (2D) with host arrays.

Parameters
[in]n1number of elements in f1
[in]h_f1host pointer containing the column filter
[in]n2number of elements in f2
[in]h_f2host pointer containing the row filter
[in]signal
[in]expandPerforms expanded convolution if true. Default is false
array af::convolve ( const array &  signal,
const array &  filter,
bool  expand = false 
)

Convolution (1D,2D,3D).

array x = randu(5);
print(x);
array f = constant(1,3);
// 2D convolution, 3x3 filter
array c = convolve(x,f);
print(c);
Parameters
[in]signal
[in]filter
[in]expandPerforms expanded convolution if true. Default is false
array af::convolve ( const array &  signal,
unsigned  ndims,
unsigned *  dims,
const ty *  h_kernel,
bool  expand = false 
)

Convolution (1D,2D,3D) with host filter.

array x = randu(5);
print(x);
array f = constant(1,3);
// 2D convolution, 3x3 filter
float f[] = {0,1,0,1,0,1,0,1,0};
unsigned d[] = {3,3};
array c = convolve(x,2,d,f);
print(c);
Parameters
[in]signal
[in]ndimsNumber of dimensions for the filter h_kernel
[in]dimsArray containing dimension sizes of filter h_kernel
[in]h_kernelHost-side array containing the filter kernel coefficients
[in]expandPerforms expanded convolution if true. Default is false