CVR-Lib last update 20 Sep 2009

cvr::kernel1D< T > Class Template Reference

One-dimensional filter kernel. More...

#include <cvrKernel1D.h>

Inheritance diagram for cvr::kernel1D< T >:

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

Collaboration graph
[legend]

List of all members.

Public Types

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

Public Member Functions

 kernel1D ()
 kernel1D (const int from, const int to, const T &init)
 kernel1D (const int from, const int to)
 kernel1D (const vector< T > &other, const int theOffset)
 kernel1D (const kernel1D &other)
virtual ~kernel1D ()
kernel1Dcopy (const kernel1D &other)
virtual const std::string & name () const
virtual kernel1D< T > * clone () const
virtual kernel1D< T > * newInstance () const
template<class U >
kernel1DcastFrom (const kernel1D< U > &other)
kernel1D< T > & castFrom (const vector< T > &other, const int firstElement=0)
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
kernel1D< T > & mirror (const kernel1D< T > &other)
kernel1D< T > & mirror ()
bool isSymmetric () const
bool isAsymmetric () const
void computeSymmetricComponent ()
void computeSymmetricComponent (const kernel1D< T > &other)
void computeAsymmetricComponent ()
void computeAsymmetricComponent (const kernel1D< T > &other)

Protected Attributes

norm_


Detailed Description

template<class T>
class cvr::kernel1D< T >

One-dimensional filter kernel.

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

See also:
cvr::convolution).
If you instantiate a kernel1D of a fixed point type, like kernel1D<int> or kernel1D<ubyte>, you also need to consider the "norm" of the kernel (see cvr::kernel1D<T>::getNorm() and cvr::kernel1D<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 kernel1D<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 lattice1D<T>::const_iterator cvr::kernel1D< 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::lattice1D::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 lattice1D 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:
lattice1D<T>::iterator

Reimplemented from cvr::lattice1D< T >.

template<class T>
typedef lattice1D<T>::const_pointer cvr::kernel1D< T >::const_pointer

Const pointer to value_type.

Reimplemented from cvr::lattice1D< T >.

template<class T>
typedef lattice1D<T>::const_reference cvr::kernel1D< T >::const_reference

Const reference to value_type.

Reimplemented from cvr::lattice1D< T >.

template<class T>
typedef lattice1D<T>::iterator cvr::kernel1D< 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::lattice1D::begin() and cvr::lattice1D::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 lattice1D 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:
lattice1D<T>::const_iterator

Reimplemented from cvr::lattice1D< T >.

template<class T>
typedef lattice1D<T>::pointer cvr::kernel1D< T >::pointer

Pointer to value_type.

Reimplemented from cvr::lattice1D< T >.

template<class T>
typedef lattice1D<T>::reference cvr::kernel1D< T >::reference

Reference to value_type.

Reimplemented from cvr::lattice1D< T >.

template<class T>
typedef lattice1D<T>::size_type cvr::kernel1D< T >::size_type

Return type of the size() member.

Reimplemented from cvr::lattice1D< T >.

template<class T>
typedef lattice1D<T>::value_type cvr::kernel1D< T >::value_type

Type of the lattice1D elements.

Reimplemented from cvr::lattice1D< T >.


Constructor & Destructor Documentation

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

Default constructor.

template<class T>
cvr::kernel1D< T >::kernel1D ( const int  from,
const int  to,
const T &  init 
)

Construct a filter kernel indexed from from to to and initialized with the value init.

template<class T>
cvr::kernel1D< T >::kernel1D ( const int  from,
const int  to 
)

Construct a uninitialization filter kernel indexed from from to to.

Warning:
This is an interface change with the previous library. It has been done to be consistent with the more basic features of the C++ language. If you write for example "int c;", the content of c is not defined, and in the same way, if you want a kernel1D with initialized data, you have to specify explicitely the value with which the elements have to be initialized.

template<class T>
cvr::kernel1D< T >::kernel1D ( const vector< T > &  other,
const int  theOffset 
)

Construct a kernel from a one dimensional vector.

Parameters:
other the source vector
theOffset this is the index in the vector that corresponds to the index '0' in the filter kernel

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

Copy constructor.

Parameters:
other the one dimensional kernel to be copied

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

Destructor.


Member Function Documentation

template<class T>
kernel1D<T>& cvr::kernel1D< T >::castFrom ( const vector< T > &  other,
const int  firstElement = 0 
)

Copy the content of the other vector in this kernel and assign the index (firstElement) to the first element of the vector.

For example if other is a 3 dimensional vector, then castFrom(other,-1) is a 3-elements-kernel which indices lay inside [-1,1].

Parameters:
other the vector with the data to be copied
firstElement index for the first element of the vector
Returns:
a reference to this instance

template<class T>
template<class U >
kernel1D& cvr::kernel1D< T >::castFrom ( const kernel1D< 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::kernel1D< T >::getNorm(), and cvr::kernel1D< T >::norm_.

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

Clone member.

Returns:
a pointer to a copy of this object

Reimplemented from cvr::lattice1D< T >.

template<class T>
void cvr::kernel1D< T >::computeAsymmetricComponent ( const kernel1D< T > &  other  ) 

Get kernel asymmetric component of other kernel.

Each discrete function (including kernels like this one) can be decomposed into a symmetric component $x_e(n)$$ and an asymmetric component $x_e(n)$ following the equation

\[ \begin{aligned} x_e &= \frac{x(t)+x(-t)}{2} \\ x_o &= \frac{x(t)-x(-t)}{2} \\ \end{aligned} \]

This method extracts the asymmetric component of the other kernel.

Parameters:
other the kernel which will be decomposed.

template<class T>
void cvr::kernel1D< T >::computeAsymmetricComponent (  ) 

Get kernel asymmetric component.

Each discrete function (including kernels like this one) can be decomposed into a symmetric component $x_e(n)$$ and an asymmetric component $x_e(n)$ following the equation

\[ \begin{aligned} x_e &= \frac{x(t)+x(-t)}{2} \\ x_o &= \frac{x(t)-x(-t)}{2} \\ \end{aligned} \]

This method extracts the asymmetric component only

template<class T>
void cvr::kernel1D< T >::computeSymmetricComponent ( const kernel1D< T > &  other  ) 

Get kernel symmetric component of other kernel.

Each discrete function (including kernels like this one) can be decomposed into a symmetric component $x_e(n)$$ and an asymmetric component $x_e(n)$ following the equation

\[ \begin{aligned} x_e &= \frac{x(t)+x(-t)}{2} \\ x_o &= \frac{x(t)-x(-t)}{2} \\ \end{aligned} \]

This method extracts the symmetric component of the other kernel.

Parameters:
other the kernel which will be decomposed.

template<class T>
void cvr::kernel1D< T >::computeSymmetricComponent (  ) 

Get kernel symmetric component.

Each discrete function (including kernels like this one) can be decomposed into a symmetric component $x_e(n)$$ and an asymmetric component $x_e(n)$ following the equation

\[ \begin{aligned} x_e &= \frac{x(t)+x(-t)}{2} \\ x_o &= \frac{x(t)-x(-t)}{2} \\ \end{aligned} \]

This method extracts the symmetric component only

template<class T>
kernel1D& cvr::kernel1D< T >::copy ( const kernel1D< 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::kernel1D< 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 kernel1D<ubyte> can be 255, if the filter kernel don't need values greater than 1.0.

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

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

template<class T>
bool cvr::kernel1D< T >::isAsymmetric (  )  const

Check if this kernel is asymmetric, i.e.

if it is valid at(x)==-at(-x) and firstIdx() == -lastIdx()

template<class T>
bool cvr::kernel1D< T >::isSymmetric (  )  const

Check if this kernel is symmetric, i.e.

if it is valid at(x)==at(-x) and firstIdx() == -lastIdx()

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

Mirror this kernel, i.e.

at(x) = at(-x);

Returns:
a reference to this instance

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

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

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

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

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

Returns the name of this type.

Reimplemented from cvr::lattice1D< T >.

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

Create a new instance.

Returns:
a pointer to a new empty kernel instance

Reimplemented from cvr::lattice1D< T >.

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

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

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

Read the object from the given ioHandler.

Reimplemented from cvr::genericLattice1D< T >.

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

Set normalization factor.

See also:
getNorm()

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

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

Write the object in the given ioHandler.

Reimplemented from cvr::genericLattice1D< T >.


Member Data Documentation

template<class T>
T cvr::kernel1D< 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::kernel1D< T >::castFrom(), cvr::kernel1D< T >::getNorm(), and cvr::kernel1D< 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