CUDA
C/C++    Fortran   

Image filtering & convolutions

Functions

array filter (const array &image, const array &kernel)
 Image Filtering.
array medfilt (const array &image, const unsigned height=3, const unsigned width=3)
 Median filtering within window (default 3x3)
array bilateral (const array &image, const float space, const float color)
 Bilateral filtering.
array meanshift (const array &image, const float space, const float color, const int iter=5)
 Meanshift filtering.
array convolve (const array &f1, const array &f2, const array &signal, bool expand=false)
 Separable convolution (2D) with device arrays.
template<typename ty >
array convolve (unsigned n1, const ty *f1, unsigned n2, const ty *f2, const array &signal, bool expand=false)
 Separable convolution (2D) with host arrays.
array convolve (const array &signal, const array &filter, bool expand=false)
 Convolution (1D,2D,3D).
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.

Function Documentation

array af::filter ( const array &  image,
const array &  kernel 
)

Image Filtering.

       // filter (convolve) an image with a 3x3 sobel kernel
       const float h_kernel[] = { -2.0, -1.0,  0.0,
                                  -1.0,  0.0,  1.0,
                                   0.0,  1.0,  2.0 };
       array kernel = array(3,3,h_kernel);
       array img_out = filter(img_in, kernel);
Parameters:
[in]image
[in]kernelcoefficient matrix
Returns:
filtered image of same size as input
Note:
Output is same size as input. Filtering done using correlation. Array values outside bounds are assumed to have zero value (0).
array af::medfilt ( const array &  image,
const unsigned  height = 3,
const unsigned  width = 3 
)

Median filtering within window (default 3x3)

       // median filter an image with a 5x5 kernel
       array img_out = medfilt(img_in, 5, 5);

       // median filter an image with the default 3x3 kernel
       array img_out = medfilt(img_in);
Parameters:
[in]image
[in]heightof window (default 3)
[in]widthof window (default 3)
array af::bilateral ( const array &  image,
const float  space,
const float  color 
)

Bilateral filtering.

       // bilateral filter an image with color values [0-1]
       float sigma_space = 2.f;
       float sigma_color = 0.1f;
       array img_out = bilateral(img_in, sigma_space, sigma_color);

       // bilateral filter an image with color values [0-255]
       float sigma_space = 2.f;
       float sigma_color = 0.1f * 255.f;
       array img_out = bilateral(img_in, sigma_space, sigma_color);
Parameters:
[in]imageinput image
[in]spaceradius in pixels, area for filtering. note: internally space *= 1.5
[in]colordifference in color allowed, range depends on values in image
Note:
color range depends on values in the image if image is [0-1], scale color from [0-1]; if image is [0-255], scale color from [0-255];
array af::meanshift ( const array &  image,
const float  space,
const float  color,
const int  iter = 5 
)

Meanshift filtering.

       // meanshift filter an image with color values [0-1]
       float sigma_space = 3.f;
       float sigma_color = 0.2f;
       int   iterations  = 5;
       array img_out = meanshift(img_in, sigma_space, sigma_color, iterations);

       // meanshift filter an image with color values [0-255]
       float sigma_space = 3.f;
       float sigma_color = 0.2f * 255.f;
       int   iterations  = 5;
       array img_out = meanshift(img_in, sigma_space, sigma_color, iterations);
Parameters:
[in]imageinput image
[in]spaceradius in pixels, area for filtering. note: internally space *= 1.5
[in]colordifference in color allowed, range depends on values in image
[in]itermaximum number of iterations for convergence (default=5, max=100)
Note:
color range depends on values in the image if image is [0-1], scale color from [0-1]; if image is [0-255], scale color from [0-255];
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 *  f1,
unsigned  n2,
const ty *  f2,
const array &  signal,
bool  expand = false 
)

Separable convolution (2D) with host arrays.

Parameters:
[in]n1number of elements in f1
[in]f1host pointer containing the column filter
[in]n2number of elements in f2
[in]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