DIPlib Documentation - ©1995-2017 Quantitative Imaging Group, Delft University of Technology.

Convolve1d

Perform a 1D convolution

SYNOPSIS

#include "dip_linear.h"

dip_Error DIP_TPI_FUNC(dip_Convolve1d)( in, out, filter, size, filterSize, origin, flags, boundary )

DATA TYPES

integer,float

FUNCTION

This function performs a one-dimensional convolution of the input data with the given filter kernel. In general your filter will be centered around the origin. The origin is uniquely defined if the filter size is odd, but if the filter size is even you'll have to specify whether the origin of the filter lies to the left or the right. Words cannot possibly suffice here, so here is a small pictorial representation:

filter size is odd :             kernel data :     x x x x x
                                                       ^
                                                       0

filter size is even and
   DIP_CNV_LEFT is specified :   kernel data :     x x x x x x
                                                       ^
                                                       0

   DIP_CNV_RIGHT is specified :  kernel data :     x x x x x x
                                                         ^
                                                         0

When the filter size is even, one of the flags DIP_CNV_LEFT or DIP_CNV_RIGHT must be specified. When the filter size is odd both flags are ignored. It is also possible to specify the origin of the filter directly by using the DIP_CNV_USE_ORIGIN flag in combination with the origin parameter. Again a small pictorial representation:

                  0 1 2 3 4 5 6 7 8
kernel data :     x x x x x x x x x     when origin = 2
                      ^
                      0

when DIP_CNV_USE_ORIGIN is NOT specified origin is computed as follows :

filter size odd      origin = ( filterSize - 1 ) / 2
filter size even _and_
   DIP_CNV_LEFT      origin = ( filterSize / 2 ) - 1
   DIP_CNV_RIGHT     origin = filterSize / 2

The input data is copied to a temporary buffer, after which the input data is extended according to the boundary condition specified. You can use the flags DIP_CNV_HAS_BORDER to indicate that the input data already has a border. In this case you must make sure that there are enough pixels on either side of the array:

   on the left  :  ( ( filterSize - 1 ) - origin )  pixels
   on the right :  ( origin )  pixels

If DIP_CNV_HAS_BORDER is specified and in != out no auxiliary storage is used.

You must also specify the symmetry of the filter as follows:

   odd filter size    :   a  b  c  b  a      DIP_CNV_EVEN
                          a  b  c -b -a      DIP_CNV_ODD
                          a  b  c  d  e      DIP_CNV_GENERAL

   even filter size   :   a  b  c  c  b  a   DIP_CNV_EVEN
                          a  b  c -c -b -a   DIP_CNV_ODD
                          a  b  c  d  e  f   DIP_CNV_GENERAL

ARGUMENTS

Data typeNameDescription
void *inPointer to the input data
void *outPointer to the output data
void *filterPointer to the filter data
dip_intsizeSize of the input data
dip_intfilterSizeSize of the filter
dip_intoriginOrigin of the filter. Only valid in conjunction with DIP_CNV_USE_ORIGIN
dipf_ConvolveflagsA combination of the flags described above
dip_BoundaryboundaryOne of the standard boundary conditions. See Boundary conditions

SEE ALSO

General information about convolution

SeparableConvolution, SeparableFrameWork