[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

Kernel2D< ARITHTYPE > Class Template Reference

Generic 2 dimensional convolution kernel. More...

`#include <vigra/stdconvolution.hxx>`

## Public Types

typedef BasicImage< value_type >::Accessor | Accessor
typedef BasicImage< value_type >::ConstAccessor | ConstAccessor
typedef BasicImage< value_type >::const_traverser | ConstIterator
typedef BasicImage< value_type >::traverser | Iterator
typedef ARITHTYPE | value_type

## Public Member Functions

Accessor | accessor ()
ConstAccessor | accessor () const
BorderTreatmentMode | borderTreatment () const
Iterator | center ()
ConstIterator | center () const
int | height () const
void | initAveraging (int radius)
void | initDisk (int radius)
Kernel2D & | initExplicitly (BasicImage< value_type > const &image)
Kernel2D & | initExplicitly (Shape2 const &upperleft, Shape2 const &lowerright)
void | initGaussian (double std_dev)
void | initGaussian (double std_dev, value_type norm)
void | initSeparable (Kernel1D< value_type > const &kx, Kernel1D< value_type > const &ky)
template<class KernelIterator >
void | initSeparable (KernelIterator kxcenter, int xleft, int xright, KernelIterator kycenter, int yleft, int yright)
| Kernel2D ()
| Kernel2D (Kernel2D const &k)
Point2D | lowerRight () const
value_type | norm () const
void | normalize ()
void | normalize (value_type norm)
value_type & | operator() (int x, int y)
value_type | operator() (int x, int y) const
Kernel2D & | operator= (Kernel2D const &k)
InitProxy | operator= (value_type const &v)
value_type & | operator[] (Diff2D const &d)
value_type | operator[] (Diff2D const &d) const
void | setBorderTreatment (BorderTreatmentMode new_mode)
Point2D | upperLeft () const
int | width () const
| ~Kernel2D ()

## Detailed Description

template<class ARITHTYPE = double>
class vigra::Kernel2D< ARITHTYPE >

Generic 2 dimensional convolution kernel.

This kernel may be used for convolution of 2 dimensional signals.

Convolution functions access the kernel via an ImageIterator which they get by calling center(). This iterator points to the center of the kernel. The kernel's size is given by its upperLeft() (upperLeft().x <= 0, upperLeft().y <= 0) and lowerRight() (lowerRight().x >= 0, lowerRight().y >= 0) methods. The desired border treatment mode is returned by borderTreatment().

The different init functions create a kernel with the specified properties. The requirements for the kernel's value_type depend on the init function used. At least NumericTraits must be defined.

Usage:

#include <vigra/stdconvolution.hxx>
Namespace: vigra

MultiArray<2, float> src(w,h), dest(w,h);
...
// define horizontal Sobel filter
vigra::Kernel2D<float> sobel;
sobel.initExplicitly(Diff2D(-1,-1), Diff2D(1,1)) = // upper left and lower right
0.125, 0.0, -0.125,
0.25, 0.0, -0.25,
0.125, 0.0, -0.125;
convolveImage(src, dest, sobel);
vigra::Diff2D
Two dimensional difference vector.
Definition diff2d.hxx:186
vigra::RGBValue
Class for a single RGB value.
Definition rgbvalue.hxx:128
vigra::convolveImage
void convolveImage(...)
Convolve an image with the given kernel(s).

Required Interface:

value_type v = NumericTraits<value_type>::one();
vigra::Kernel2D::value_type
ARITHTYPE value_type
Definition stdconvolution.hxx:765

See also the init functions.

## Member Typedef Documentation

## ◆ value_type

template<class ARITHTYPE = double>

typedef ARITHTYPE value_type

the kernel's value type

## ◆ Iterator

template<class ARITHTYPE = double>

typedef BasicImage<value_type>::traverser Iterator

2D random access iterator over the kernel's values

## ◆ ConstIterator

template<class ARITHTYPE = double>

typedef BasicImage<value_type>::const_traverser ConstIterator

const 2D random access iterator over the kernel's values

## ◆ Accessor

template<class ARITHTYPE = double>

typedef BasicImage<value_type>::Accessor Accessor

the kernel's accessor

## ◆ ConstAccessor

template<class ARITHTYPE = double>

typedef BasicImage<value_type>::ConstAccessor ConstAccessor

the kernel's const accessor

## Constructor & Destructor Documentation

## ◆ Kernel2D() [1/2]

template<class ARITHTYPE = double>

Kernel2D | ( |  | ) |

Default constructor. Creates a kernel of size 1x1 which would copy the signal unchanged.

## ◆ Kernel2D() [2/2]

template<class ARITHTYPE = double>

Kernel2D | ( | Kernel2D< ARITHTYPE > const & | k | ) |

Copy constructor.

## ◆ ~Kernel2D()

template<class ARITHTYPE = double>

~Kernel2D | ( |  | ) |

Destructor.

## Member Function Documentation

## ◆ operator=() [1/2]

template<class ARITHTYPE = double>

Kernel2D & operator= | ( | Kernel2D< ARITHTYPE > const & | k | ) |

Copy assignment.

## ◆ operator=() [2/2]

template<class ARITHTYPE = double>

InitProxy operator= | ( | value_type const & | v | ) |

Initialization. This initializes the kernel with the given constant. The norm becomes v*width()*height().

Instead of a single value an initializer list of length width()*height() can be used like this:

vigra::Kernel2D<float> binom;
binom.initExplicitly(Diff2D(-1,-1), Diff2D(1,1)) =
0.0625, 0.125, 0.0625,
0.125, 0.25, 0.125,
0.0625, 0.125, 0.0625;

In this case, the norm will be set to the sum of the init values. An initializer list of wrong length will result in a run-time error.

## ◆ initSeparable() [1/2]

template<class ARITHTYPE = double>

void initSeparable | ( | Kernel1D< value_type > const & | kx,
|  | Kernel1D< value_type > const & | ky
| ) |  |

Init the 2D kernel as the cartesian product of two 1D kernels of type Kernel1D. The norm becomes the product of the two original norms.

Required Interface:

The kernel's value_type must be a linear algebra.

vigra::Kernel2D<...>::value_type v;
v = v * v;
vigra::Kernel2D
Generic 2 dimensional convolution kernel.
Definition stdconvolution.hxx:761

## ◆ initSeparable() [2/2]

template<class ARITHTYPE = double>
template<class KernelIterator >

void initSeparable | ( | KernelIterator | kxcenter,
|  | int | xleft,
|  | int | xright,
|  | KernelIterator | kycenter,
|  | int | yleft,
|  | int | yright
| ) |  |

Init the 2D kernel as the cartesian product of two 1D kernels given explicitly by iterators and sizes. The norm becomes the sum of the resulting kernel values.

Required Interface:

The kernel's value_type must be a linear algebra.

vigra::Kernel2D<...>::value_type v;
v = v * v;
v += v;

Preconditions:

xleft <= 0;
xright >= 0;
yleft <= 0;
yright >= 0;

## ◆ initAveraging()

template<class ARITHTYPE = double>

void initAveraging | ( | int | radius | ) |

Init as a 2D box filter with given radius.

## ◆ initGaussian() [1/2]

template<class ARITHTYPE = double>

void initGaussian | ( | double | std_dev,
|  | value_type | norm
| ) |  |

Init as a 2D Gaussian function with given standard deviation and norm.

## ◆ initGaussian() [2/2]

template<class ARITHTYPE = double>

void initGaussian | ( | double | std_dev | ) |

Init as a 2D Gaussian function with given standard deviation and unit norm.

## ◆ initDisk()

template<class ARITHTYPE = double>

void initDisk | ( | int | radius | ) |

Init the 2D kernel as a circular averaging filter. The norm will be calculated as `NumericTraits<value_type>::one() / (number of non-zero kernel values)`. The kernel's value_type must be a linear space.

Required Interface:

value_type v = vigra::NumericTraits<value_type>::one();
double d;
v = d * v;

Precondition:

radius > 0;

## ◆ initExplicitly() [1/2]

template<class ARITHTYPE = double>

Kernel2D & initExplicitly | ( | Shape2 const & | upperleft,
|  | Shape2 const & | lowerright
| ) |  |

Init the kernel by an explicit initializer list. The upper left and lower right corners (inclusive) of the kernel must be passed either as `Shape2` or `Diff2D` objects. A comma-separated initializer list for the kernel's weights is given after the assignment operator like this:

// define horizontal Sobel filter
vigra::Kernel2D<float> sobel;
sobel.initExplicitly(Diff2D(-1,-1), Diff2D(1,1)) =
0.125, 0.0, -0.125,
0.25, 0.0, -0.25,
0.125, 0.0, -0.125;

The norm is set to the sum of the initializer values. If the wrong number of values is given, a run-time error results. It is, however, possible to give just one initializer. This creates an averaging filter with the given constant:

vigra::Kernel2D<float> average3x3;
average3x3.initExplicitly(Shape2(-1,-1), Shape2(1,1)) = 1.0/9.0;

Here, the norm is set to value*width()*height().

Preconditions:

1. upperleft.x <= 0;
2. upperleft.y <= 0;
3. lowerright.x >= 0;
4. lowerright.y >= 0;
5. the number of values in the initializer list
is 1 or equals the size of the kernel.

## ◆ initExplicitly() [2/2]

template<class ARITHTYPE = double>

Kernel2D & initExplicitly | ( | BasicImage< value_type > const & | image | ) |

Init the kernel by providing a BasicImage with the kernel values.

The kernel's origin is placed at the center of the given image. The norm is set to the sum of the image values.

Preconditions:

odd image width and height;

## ◆ upperLeft()

template<class ARITHTYPE = double>

Point2D upperLeft | ( |  | ) | const

Coordinates of the upper left corner of the kernel.

## ◆ lowerRight()

template<class ARITHTYPE = double>

Point2D lowerRight | ( |  | ) | const

Coordinates of the lower right corner of the kernel.

## ◆ width()

template<class ARITHTYPE = double>

int width | ( |  | ) | const

Width of the kernel.

## ◆ height()

template<class ARITHTYPE = double>

int height | ( |  | ) | const

Height of the kernel.

## ◆ center() [1/2]

template<class ARITHTYPE = double>

Iterator center | ( |  | ) |

ImageIterator that points to the center of the kernel (coordinate (0,0)).

## ◆ center() [2/2]

template<class ARITHTYPE = double>

ConstIterator center | ( |  | ) | const

ImageIterator that points to the center of the kernel (coordinate (0,0)).

## ◆ operator()() [1/2]

template<class ARITHTYPE = double>

value_type & operator() | ( | int | x,
|  | int | y
| ) |  |

Access kernel entry at given position.

## ◆ operator()() [2/2]

template<class ARITHTYPE = double>

value_type operator() | ( | int | x,
|  | int | y
| ) |  | const

Read kernel entry at given position.

## ◆ operator[]() [1/2]

template<class ARITHTYPE = double>

value_type & operator[] | ( | Diff2D const & | d | ) |

Access kernel entry at given position.

## ◆ operator[]() [2/2]

template<class ARITHTYPE = double>

value_type operator[] | ( | Diff2D const & | d | ) | const

Read kernel entry at given position.

## ◆ norm()

template<class ARITHTYPE = double>

value_type norm | ( |  | ) | const

Norm of the kernel (i.e. sum of its elements).

## ◆ accessor() [1/2]

template<class ARITHTYPE = double>

Accessor accessor | ( |  | ) |

The kernels default accessor.

## ◆ accessor() [2/2]

template<class ARITHTYPE = double>

ConstAccessor accessor | ( |  | ) | const

The kernels default const accessor.

## ◆ normalize() [1/2]

template<class ARITHTYPE = double>

void normalize | ( | value_type | norm | ) |

Normalize the kernel to the given value. (The norm is the sum of all kernel elements.) The kernel's value_type must be a division algebra or algebraic field.

Required Interface:

value_type v = vigra::NumericTraits<value_type>::one(); // if norm is not
// given explicitly
v += v;
v = v * v;
v = v / v;

## ◆ normalize() [2/2]

template<class ARITHTYPE = double>

void normalize | ( |  | ) |

Normalize the kernel to norm 1.

## ◆ borderTreatment()

template<class ARITHTYPE = double>

BorderTreatmentMode borderTreatment | ( |  | ) | const

current border treatment mode

## ◆ setBorderTreatment()

template<class ARITHTYPE = double>

void setBorderTreatment | ( | BorderTreatmentMode | new_mode | ) |

Set border treatment mode. Only `BORDER_TREATMENT_CLIP` and `BORDER_TREATMENT_AVOID` are currently allowed.

The documentation for this class was generated from the following file:

- vigra/stdconvolution.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.12.1