CVR-Lib last update 20 Sep 2009

cvr::kernel2D< T > Class Template Reference

Two-dimensional filter kernel. More...

#include <cvrKernel2D.h>

Inheritance diagram for cvr::kernel2D< T >:

Inheritance graph
[legend]
Collaboration diagram for cvr::kernel2D< T >:

Collaboration graph
[legend]

List of all members.

Public Types

Internal types and classes
typedef lattice2D< T >::value_type value_type
typedef lattice2D< T >::size_type size_type
typedef lattice2D< T >::pointer pointer
typedef lattice2D< T >
::const_pointer 
const_pointer
typedef lattice2D< T >::reference reference
typedef lattice2D< T >
::const_reference 
const_reference
typedef lattice2D< T >::iterator iterator
typedef lattice2D< T >
::const_iterator 
const_iterator

Public Member Functions

 kernel2D ()
 kernel2D (const int fromRow, const int fromCol, const int toRow, const int toCol)
 kernel2D (const size_type &from, const size_type &to)
 kernel2D (const iinterval &rows, const iinterval &columns)
 kernel2D (const int fromRow, const int fromCol, const int toRow, const int toCol, const T &value)
 kernel2D (const size_type &from, const size_type &to, const T &value)
 kernel2D (const iinterval &rows, const iinterval &columns, const T &value)
 kernel2D (const int fromRow, const int fromCol, const int toRow, const int toCol, const T data[])
 kernel2D (const size_type &from, const size_type &to, const T data[])
 kernel2D (const iinterval &rows, const iinterval &columns, const T data[])
 kernel2D (const int fromRow, const int fromCol, const int toRow, const int toCol, T data[], const eConstantReference constRef)
 kernel2D (const size_type &from, const size_type &to, T data[], const eConstantReference constRef)
 kernel2D (const iinterval &rows, const iinterval &columns, T data[], const eConstantReference constRef)
 kernel2D (const genericLattice2D< T > &other)
 kernel2D (const genericLattice2D< T > &other, const int fromRow, const int fromCol, const int toRow=container::MaxIndex, const int toCol=container::MaxIndex)
 kernel2D (const genericLattice2D< T > &other, const size_type &from, const size_type &to)
 kernel2D (const genericLattice2D< T > &other, const iinterval &rows, const iinterval &columns)
 kernel2D (const genericLattice2D< T > &other, const genericLattice1D< int > &rows)
 kernel2D (const kernel2D &other)
virtual ~kernel2D ()
kernel2Dcopy (const kernel2D &other)
virtual const std::string & name () const
virtual kernel2D< T > * clone () const
virtual kernel2D< T > * newInstance () const
template<class U >
kernel2DcastFrom (const kernel2D< U > &other)
const T & getNorm () const
void setNorm (const T &n)
void normalize ()
virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)
Symmetries
kernel2D< T > & mirror (const kernel2D< T > &other)
kernel2D< T > & mirror ()

Protected Attributes

norm_


Detailed Description

template<class T>
class cvr::kernel2D< T >

Two-dimensional filter kernel.

The template type of this class should coincide with the template class of the matrix to be convolved with. For example, if you want to convolve a kernel2D with a matrix<double>, you will need a kernel2D<double> (

See also:
cvr::convolution).
If you instantiate a kernel2D of a fixed point type, like kernel2D<int> or kernel2D<ubyte>, you also need to consider the "norm" of the kernel (see cvr::kernel2D<T>::getNorm() and cvr::kernel2D<T>::setNorm(const T&)). This "norm" allows the representation of numbers less than 1.0. You can see this norm as the value to be considered as 1.0, when operating with the kernel. For example, if you have a kernel2D<ubyte> with the values [64,128,64] and norm=255, the the interpreted values during convolution will be [0.25,0.5,0.25]. With floating-point types, the norm will be always assumed to be 1.0. For other types the default norms are the following:

For int: 65536 For ubyte: 255 Otherwise: 1.0

See also:
cvr::convolution

Member Typedef Documentation

template<class T>
typedef lattice2D<T>::const_iterator cvr::kernel2D< T >::const_iterator

const_iterator type (allows read-only operations).

The use of the iterator classes is similar to the iterators of the STL (Standard Template Library). See cvr::lattice2D::begin() for an example.

For the debugging version of the iterators, boundary check will be done! This explains the low speed of the iterators of the debug version. In the release version, no boundary check will be done, and the iterators are sometimes a factor 10 faster than the debug iterators.

The use of the access operator at() is faster than the iterators in the debug version only. If you need to iterate on a lattice2D use iterators instead (in the release version iterators are approximately a factor 3 faster than at()).

Warning:
Try to use the prefix incremental operator (i.e. ++it) instead of the postfix operator (i.e. it++) to allow efficient code also in debug-modus!
See also:
lattice2D<T>::iterator

Reimplemented from cvr::lattice2D< T >.

template<class T>
typedef lattice2D<T>::const_pointer cvr::kernel2D< T >::const_pointer

Const pointer to value_type.

Reimplemented from cvr::lattice2D< T >.

template<class T>
typedef lattice2D<T>::const_reference cvr::kernel2D< T >::const_reference

Const reference to value_type.

Reimplemented from cvr::lattice2D< T >.

template<class T>
typedef lattice2D<T>::iterator cvr::kernel2D< T >::iterator

iterator type (allows read and write operations).

The use of the iterator classes is similar to the iterators of the STL (Standard Template Library). See cvr::lattice2D::begin() and cvr::lattice2D::inverseBegin() for examples.

For the debugging version of the iterators, boundary check will be done! This explains the low speed of the iterators of the debug version. In the release version, no boundary check will be done, and the iterators are sometimes a factor 10 faster than the debug iterators.

The use of the access operator at() is faster than the iterators in the debug version only. If you need to iterate on a lattice2D use iterators instead (in the release version iterators are approximately a factor 3 faster than at()).

Warning:
Try to use the prefix incremental operator (i.e. ++it) instead of the postfix operator (i.e. it++) to allow efficient code also in debug-modus!
See also:
lattice2D<T>::const_iterator

Reimplemented from cvr::lattice2D< T >.

template<class T>
typedef lattice2D<T>::pointer cvr::kernel2D< T >::pointer

Pointer to value_type.

Reimplemented from cvr::lattice2D< T >.

template<class T>
typedef lattice2D<T>::reference cvr::kernel2D< T >::reference

Reference to value_type.

Reimplemented from cvr::lattice2D< T >.

template<class T>
typedef lattice2D<T>::size_type cvr::kernel2D< T >::size_type

Return type of the size() member.

Reimplemented from cvr::lattice2D< T >.

template<class T>
typedef lattice2D<T>::value_type cvr::kernel2D< T >::value_type

Type of the lattice2D elements.

Reimplemented from cvr::lattice2D< T >.


Constructor & Destructor Documentation

template<class T>
cvr::kernel2D< T >::kernel2D (  ) 

Default constructor creates an empty kernel2D.

template<class T>
cvr::kernel2D< T >::kernel2D ( const int  fromRow,
const int  fromCol,
const int  toRow,
const int  toCol 
)

Create a kernel2D with uninitialized elements.

Parameters:
fromRow lowest row index
fromCol lowest column index
toRow highest row index (inclusive)
toCol highest column index (inclusive)

template<class T>
cvr::kernel2D< T >::kernel2D ( const size_type from,
const size_type to 
)

Create a rows x cols kernel2D with uninitialized elements.

Parameters:
from lowest index
to highest index (inclusive)

template<class T>
cvr::kernel2D< T >::kernel2D ( const iinterval rows,
const iinterval columns 
)

Create a kernel2D with uninitialized elements.

Parameters:
rows interval used for the rows
columns interval used for the columns

template<class T>
cvr::kernel2D< T >::kernel2D ( const int  fromRow,
const int  fromCol,
const int  toRow,
const int  toCol,
const T &  value 
)

Create a kernel2D and initialize all elements with the given value.

Parameters:
fromRow lowest row index
fromCol lowest column index
toRow highest row index (inclusive)
toCol highest column index (inclusive)
value value used for initializing the elements

template<class T>
cvr::kernel2D< T >::kernel2D ( const size_type from,
const size_type to,
const T &  value 
)

Create a kernel2D and initialize all elements with the given value.

Parameters:
from lowest index
to highest index (inclusive)
value value used for initializing the elements

template<class T>
cvr::kernel2D< T >::kernel2D ( const iinterval rows,
const iinterval columns,
const T &  value 
)

Create a kernel2D and initialize all elements with the given value.

Parameters:
rows interval used for the rows
columns interval used for the columns
value value used for initializing the elements

template<class T>
cvr::kernel2D< T >::kernel2D ( const int  fromRow,
const int  fromCol,
const int  toRow,
const int  toCol,
const T  data[] 
)

Create a kernel2D and initialize all elements with the data pointed by data.

The first elements of the data will be copied on the first row, the next ones on the second row and so on.

Parameters:
fromRow lowest row index
fromCol lowest column index
toRow highest row index (inclusive)
toCol highest column index (inclusive)
data pointer to the memory block with the data to be initialized with.

template<class T>
cvr::kernel2D< T >::kernel2D ( const size_type from,
const size_type to,
const T  data[] 
)

Create a kernel2D and initialize all elements with the data pointed by data.

The first elements of the data will be copied on the first row, the next ones on the second row and so on.

Parameters:
from lowest index
to highest index (inclusive)
data pointer to the memory block with the data to be initialized with.

template<class T>
cvr::kernel2D< T >::kernel2D ( const iinterval rows,
const iinterval columns,
const T  data[] 
)

Create a kernel2D and initialize all elements with the data pointed by data.

The first elements of the data will be copied on the first row, the next ones on the second row and so on.

Parameters:
rows interval used for the rows
columns interval used for the columns
data pointer to the memory block with the data to be initialized with.

template<class T>
cvr::kernel2D< T >::kernel2D ( const int  fromRow,
const int  fromCol,
const int  toRow,
const int  toCol,
data[],
const eConstantReference  constRef 
)

Create a kernel2D and use the given data as if it was given through the useExternData().

See also:
useExternData()
The first elements of the data will be copied on the first row, the next ones on the second row and so on.

Note:
Please observe that the last argument makes a huge difference to the constructors that do not have it. Here the data is not copied, just a reference is kept. Without the last argument, the data is always copied.
Parameters:
fromRow lowest row index
fromCol lowest column index
toRow highest row index (inclusive)
toCol highest column index (inclusive)
data pointer to the memory block with the data to be initialized with.
constRef usually you want this value to be ConstantReference.

template<class T>
cvr::kernel2D< T >::kernel2D ( const size_type from,
const size_type to,
data[],
const eConstantReference  constRef 
)

Create a kernel2D and use the given data as if it was given through the useExternData().

See also:
useExternData()
The first elements of the data will be copied on the first row, the next ones on the second row and so on.

Note:
Please observe that the last argument makes a huge difference to the constructors that do not have it. Here the data is not copied, just a reference is kept. Without the last argument, the data is always copied.
Parameters:
from lowest index
to highest index (inclusive)
data pointer to the memory block with the data to be initialized with.
constRef usually you want this value to be ConstantReference.

template<class T>
cvr::kernel2D< T >::kernel2D ( const iinterval rows,
const iinterval columns,
data[],
const eConstantReference  constRef 
)

Create a kernel2D and use the given data as if it was given through the useExternData().

See also:
useExternData()
The first elements of the data will be copied on the first row, the next ones on the second row and so on.

Note:
Please observe that the last argument makes a huge difference to the constructors that do not have it. Here the data is not copied, just a reference is kept. Without the last argument, the data is always copied.
Parameters:
rows interval for rows
columns interval for columns
data pointer to the memory block with the data to be initialized with.
constRef usually you want this value to be ConstantReference.

template<class T>
cvr::kernel2D< T >::kernel2D ( const genericLattice2D< T > &  other  ) 

Copy constructor.

Create this kernel2D as a copy of another kernel2D.

Parameters:
other the kernel2D to be copied.

template<class T>
cvr::kernel2D< T >::kernel2D ( const genericLattice2D< T > &  other,
const int  fromRow,
const int  fromCol,
const int  toRow = container::MaxIndex,
const int  toCol = container::MaxIndex 
)

Copy constructor.

Create this kernel2D as a copy of another kernel2D for this const version, the data will be always copied!

Parameters:
other the genericLattice2D to be copied.
fromRow initial row of the other genericLattice2D to be copied
fromCol initial column of the other genericLattice2D to be copied
toRow last row to be copied of the other genericLattice2D
toCol last column to be copied of the other genericLattice2D

template<class T>
cvr::kernel2D< T >::kernel2D ( const genericLattice2D< T > &  other,
const size_type from,
const size_type to 
)

Copy constructor.

Create this kernel2D as a copy of a section of another kernel2D

Parameters:
other the genericLattice2D to be copied.
from initial position in the other genericLattice2D to be copied
to last position to be copied of the other genericLattice2D

template<class T>
cvr::kernel2D< T >::kernel2D ( const genericLattice2D< T > &  other,
const iinterval rows,
const iinterval columns 
)

Copy constructor.

Create this kernel2D as a copy of a sublattice2D of another genericLattice2D.

Parameters:
other the genericLattice2D to be copied.
rows interval of rows to be copied.
columns interval of columns to be copied.

template<class T>
cvr::kernel2D< T >::kernel2D ( const genericLattice2D< T > &  other,
const genericLattice1D< int > &  rows 
)

Copy constructor.

Create this kernel2D as a copy of another genericLattice2D taking only the rows indicated by the vector.

The data will be always copied! Multiple occurence of one row index in rows is allowed.

Parameters:
other the genericLattice2D to be copied.
rows indices of the rows to be copied

template<class T>
cvr::kernel2D< T >::kernel2D ( const kernel2D< T > &  other  ) 

Copy constructor.

Parameters:
other the one dimensional kernel to be copied

template<class T>
virtual cvr::kernel2D< T >::~kernel2D (  )  [virtual]

Destructor.


Member Function Documentation

template<class T>
template<class U >
kernel2D& cvr::kernel2D< T >::castFrom ( const kernel2D< U > &  other  )  [inline]

Copy from kernel of different type.

Parameters:
other a one dimensional kernel of another type
Returns:
a reference to this instance

References cvr::kernel2D< T >::getNorm(), and cvr::kernel2D< T >::norm_.

template<class T>
virtual kernel2D<T>* cvr::kernel2D< T >::clone (  )  const [virtual]

Clone member.

Returns:
a pointer to a copy of this object

Reimplemented from cvr::lattice2D< T >.

template<class T>
kernel2D& cvr::kernel2D< T >::copy ( const kernel2D< T > &  other  ) 

Copy member.

Parameters:
other the one dimensional kernel to be copied
Returns:
a reference to this instance

template<class T>
const T& cvr::kernel2D< T >::getNorm (  )  const [inline]

Get normalization factor.

The normalization factor is used by the fixed point types as a representation of the value 1. For example, the norm for a kernel2D<ubyte> can be 255, if the filter kernel don't need values greater than 1.0.

References cvr::kernel2D< T >::norm_.

Referenced by cvr::kernel2D< T >::castFrom().

template<class T>
kernel2D<T>& cvr::kernel2D< T >::mirror (  ) 

Mirror this kernel, i.e.

at(x,y) = at(-x,-y);

Returns:
a reference to this instance

template<class T>
kernel2D<T>& cvr::kernel2D< T >::mirror ( const kernel2D< T > &  other  ) 

Mirror the other kernel and leave the result here, i.e.

at(x,y) = other.at(-x,-y);

Parameters:
other the kernel to be copied and then mirrored
Returns:
a reference to this instance

template<class T>
virtual const std::string& cvr::kernel2D< T >::name (  )  const [virtual]

Returns the name of this type.

Reimplemented from cvr::lattice2D< T >.

template<class T>
virtual kernel2D<T>* cvr::kernel2D< T >::newInstance (  )  const [virtual]

Create a new instance.

Returns:
a pointer to a new empty kernel instance

Reimplemented from cvr::lattice2D< T >.

template<class T>
void cvr::kernel2D< T >::normalize (  ) 

Normalize divides all elements by the norm and sets the norm to 1!

template<class T>
virtual bool cvr::kernel2D< T >::read ( ioHandler handler,
const bool  complete = true 
) [virtual]

Read the object from the given ioHandler.

Reimplemented from cvr::genericLattice2D< T >.

template<class T>
void cvr::kernel2D< T >::setNorm ( const T &  n  )  [inline]

Set normalization factor.

See also:
getNorm()

References cvr::kernel2D< T >::norm_.

template<class T>
virtual bool cvr::kernel2D< T >::write ( ioHandler handler,
const bool  complete = true 
) const [virtual]

Write the object in the given ioHandler.

Reimplemented from cvr::genericLattice2D< T >.


Member Data Documentation

template<class T>
T cvr::kernel2D< T >::norm_ [protected]

Normalization factor.

This value will be ignored for floating point formats. For fixed point formats, this value corresponds to 1.0

Referenced by cvr::kernel2D< T >::castFrom(), cvr::kernel2D< T >::getNorm(), and cvr::kernel2D< T >::setNorm().


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

Generated on Sun Sep 20 22:08:47 2009 for CVR-Lib by Doxygen 1.5.8