A Survey of Gaussian Convolution Algorithms
Functions
Box filter Gaussian convolution

A fast low-accuracy approximation of Gaussian convolution. More...

Detailed Description

A fast low-accuracy approximation of Gaussian convolution.

This code implements the basic iterated box filter approximation of Gaussian convolution as developed by Wells. This approach is based on the efficient recursive implementation of the box filter as

\[ H(z) = \frac{1}{2r + 1}\frac{z^r - z^{-r-1}}{1 - z^{-1}}, \]

where r is the box radius.

While box filtering is very efficient, it has the limitation that only a quantized set of $ \sigma $ values can be approximated because the box radius r is integer. Extended box filter Gaussian convolution and Stacked integral images Gaussian convolution are extensions of box filtering that allow $ \sigma $ to vary continuously.

Example
buffer = (num *)malloc(sizeof(num) * N);
free(buffer);
Reference
  • W.M. Wells, "Efficient synthesis of Gaussian filters by cascaded uniform filters," IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 8, no. 2, pp. 234-239, 1986. http://dx.doi.org/10.1109/TPAMI.1986.4767776

Functions

static void box_filter (num *dest, long dest_stride, const num *src, long src_stride, long N, long r)
 Perform one pass of box filtering. More...
 
void box_gaussian_conv (num *dest, num *buffer, const num *src, long N, long stride, num sigma, int K)
 Box filtering approximation of Gaussian convolution. More...
 
void box_gaussian_conv_image (num *dest, num *buffer, const num *src, int width, int height, int num_channels, num sigma, int K)
 Box filtering approximation of 2D Gaussian convolution. More...
 

Function Documentation

static void box_filter ( num dest,
long  dest_stride,
const num src,
long  src_stride,
long  N,
long  r 
)
static

Perform one pass of box filtering.

Parameters
destdestination array
dest_stridestride between successive samples of dest
src_stridesrc array (must be distinct from dest)
src_stridestride between successive samples of src
Nnumber of samples
rradius of the box filter

Performs one pass of box filtering with radius r (diameter 2r+1) according to the recursive filter

\[ H(z) = \frac{1}{2r+1} \frac{z^r - z^{-r-1}}{1 - z^{-1}}. \]

Note
The computation is out-of-place, src and dest must be distinct.

Definition at line 43 of file gaussian_conv_box.c.

void box_gaussian_conv ( num dest_data,
num buffer_data,
const num src,
long  N,
long  stride,
num  sigma,
int  K 
)

Box filtering approximation of Gaussian convolution.

Parameters
dest_datadestination array
buffer_dataarray with space for at least N samples
srcinput, overwritten if src = dest_data
Nnumber of samples
stridestride between successive samples
sigmaGaussian standard deviation in pixels
Knumber of box filter passes
Note
This routine can only approximate Gaussian convolution for a quantized set of $ \sigma $ values. The input argument sigma is rounded to the closest supported value.

This routine performs iterated box filtering approximation of Gaussian convolution. Well's approximation $ \sigma^2 = \tfrac{1}{12} K \bigl((2r+1)^2 - 1\bigr) $ is used to select the box filter radius.

The filtering itself is performed by calling the box_filter() function K times. Since box_filter() requires that the source and destination arrays are distinct, the iteration alternates the roles of the dest and buffer arrays. For example the iteration pseudocode for K = 4 is

    buffer <- box_filter(src)
    dest   <- box_filter(buffer)
    buffer <- box_filter(dest)
    dest   <- box_filter(buffer)
    dest   <- dest * scale

The convolution can be performed in-place by setting src = dest (the source array is overwritten with the result). However, buffer_data must be distinct from dest_data.

Definition at line 105 of file gaussian_conv_box.c.

void box_gaussian_conv_image ( num dest,
num buffer,
const num src,
int  width,
int  height,
int  num_channels,
num  sigma,
int  K 
)

Box filtering approximation of 2D Gaussian convolution.

Parameters
destdestination image
bufferarray with at least max(width,height) samples
srcinput, overwritten if src = dest
widthimage width
heightimage height
num_channelsnumber of image channels
sigmaGaussian standard deviation in pixels
Knumber of box filter passes

Similar to box_gaussian_conv(), this routine approximates 2D Gaussian convolution with box filtering.

The convolution can be performed in-place by setting src = dest (the source array is overwritten with the result). However, buffer must be distinct from dest.

Definition at line 195 of file gaussian_conv_box.c.