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

details Kernel2D Class Template Reference VIGRA

Generic 2 dimensional convolution kernel. More...

#include "vigra/stdconvolution.hxx"


Public Types

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

Public Methods

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


Detailed Description


template<class ARITHTYPE>
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(). (Note that the 2D convolution functions don't currently support all modes.)

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.

The kernel defines a factory function kernel2d() to create an argument object (see Kernel Argument Object Factories).

Usage:

#include "vigra/stdconvolution.hxx"
Namespace: vigra

    vigra::FImage 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;

    vigra::convolveImage(srcImageRange(src), destImage(dest), kernel2d(sobel));

Required Interface:

    value_type v = NumericTraits<value_type>::one();

See also the init functions.


Member Typedef Documentation


typedef BasicImage<value_type>::Accessor Accessor

 

the kernel's accessor


typedef BasicImage<value_type>::ConstAccessor ConstAccessor

 

the kernel's const accessor


typedef BasicImage<value_type>::const_traverser ConstIterator

 

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


typedef BasicImage<value_type>::traverser Iterator

 

2D random access iterator over the kernel's values


typedef ARITHTYPE value_type

 

the kernel's value type


Constructor & Destructor Documentation


Kernel2D   [inline]

 

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


Kernel2D Kernel2D< ARITHTYPE > const &    k [inline]

 

Copy constructor.


~Kernel2D   [inline]

 

Destructor.


Member Function Documentation


ConstAccessor accessor   const [inline]

 

The kernels default const accessor.


Accessor accessor   [inline]

 

The kernels default accessor.


BorderTreatmentMode borderTreatment   const [inline]

 

current border treatment mode


ConstIterator center   const [inline]

 

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


Iterator center   [inline]

 

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


int height   const [inline]

 

Height of the kernel.


void initDisk int    radius [inline]

 

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;


Kernel2D& initExplicitly Diff2D    upperleft,
Diff2D    lowerright
[inline]

 

Init the kernel by an explicit initializer list. The upper left and lower right corners of the kernel must be passed. A comma-separated initializer list is given after the assignment operator. This function is used 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 initialzer 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(Diff2D(-1,-1), Diff2D(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.


void initSeparable KernelIterator    kxcenter,
int    xleft,
int    xright,
KernelIterator    kycenter,
int    yleft,
int    yright
[inline]

 

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;


void initSeparable Kernel1D< value_type > &    kx,
Kernel1D< value_type > &    ky
[inline]

 

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;


Point2D lowerRight   const [inline]

 

Coordinates of the lower right corner of the kernel.


value_type norm   const [inline]

 

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


void normalize   [inline]

 

Normalize the kernel to norm 1.


void normalize value_type    norm [inline]

 

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;


value_type operator() int    x,
int    y
const [inline]

 

Read kernel entry at given position.


value_type& operator() int    x,
int    y
[inline]

 

Access kernel entry at given position.


InitProxy operator= value_type const &    v [inline]

 

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.


Kernel2D& operator= Kernel2D< ARITHTYPE > const &    k [inline]

 

Copy assignment.


value_type operator[] Diff2D const &    d const [inline]

 

Read kernel entry at given position.


value_type& operator[] Diff2D const &    d [inline]

 

Access kernel entry at given position.


void setBorderTreatment BorderTreatmentMode    new_mode [inline]

 

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


Point2D upperLeft   const [inline]

 

Coordinates of the upper left corner of the kernel.


int width   const [inline]

 

Width of the kernel.


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

© Ullrich Köthe (koethe@informatik.uni-hamburg.de)
Cognitive Systems Group, University of Hamburg, Germany

html generated using doxygen and Python
VIGRA 1.5.0 (7 Dec 2006)