CVR-Lib last update 20 Sep 2009

cvr::separableKernel< T > Class Template Reference

Separable Kernel. More...

#include <cvrSeparableKernel.h>

Inheritance diagram for cvr::separableKernel< T >:

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

Collaboration graph
[legend]

List of all members.

Classes

struct  kernelPair
 A pair of 1D kernels. More...

Public Member Functions

 separableKernel ()
 separableKernel (const separableKernel &other)
 separableKernel (const int from, const int to, const T &iniValue=T())
 separableKernel (const kernel1D< T > &subkernel)
virtual ~separableKernel ()
separableKernelcopy (const separableKernel &other)
virtual const std::string & name () const
virtual separableKernelclone () const
virtual separableKernelnewInstance () const
template<class U >
separableKernelcastFrom (const separableKernel< U > &other)
bool separate (const kernel2D< T > &k, const double &maxDev=0.01)
int getNumberOfPairs () const
void setNumberOfPairs (const int numPairs)
kernel1D< T > & getRowFilter (const int i)
kernel1D< T > & getColumnFilter (const int i)
const kernel1D< T > & getRowFilter (const int i) const
const kernel1D< T > & getColumnFilter (const int i) const
void normalize ()
separableKernel< T > & multiply (const T &value)
void setNorm (const T &newNorm)
computeSumOfElements () const
separableKernel< T > & mirror (const separableKernel< T > &other)
separableKernel< T > & mirror ()
virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)
Apply Methods
separableKernel< T > & apply (T(*function)(T))
separableKernel< T > & apply (T(*function)(const T &))
separableKernel< T > & apply (const separableKernel< T > &other, T(*function)(T))
separableKernel< T > & apply (const separableKernel< T > &other, T(*function)(const T &))

Protected Attributes

std::vector< kernelPairkernels_


Detailed Description

template<class T>
class cvr::separableKernel< T >

Separable Kernel.

A separable kernel is a vector of one dimensional kernels. If a two dimensional kernel can be separated, the convolution can be applied in a very efficient way.

A filter kernel K is called separable "in one pair", if the matrix representation of K can be produced as an outer product of two one-dimensional kernels Kx and Ky.

The template type of this class should coincide with the template class of the matrix or channel to be convolved with. For example, if you want to convolve a separableKernel with a cvr::channel, you will need a separableKernel<channel::value_type> or separableKernel<float>.

If you instantiate a separableKernel of a fixed point type, like separableKernel<int> or separableKernel<ubyte>, you also need to consider the "norm" of the kernel (see cvr::separableKernel<T>::getNorm() and cvr::separableKernel<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 consider as 1.0, when operating with the kernel. For example, if you have a separableKernel<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: (see cvr::typeInfo)

See also:
convolution

Constructor & Destructor Documentation

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

Default constructor.

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

Copy constructor.

Parameters:
other the kernel to be copied.

template<class T>
cvr::separableKernel< T >::separableKernel ( const int  from,
const int  to,
const T &  iniValue = T() 
)

Construct a separable kernel with one filter pair, all elements of the subfilters initialized with the given value.

Parameters:
from first index of the one dimensional filter kernel
to last index of the one dimensional filter kernel
iniValue initial value for the kernel elements

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

Construct a symmetrical separable kernel.

The resulting separable kernel will have just one filter pair, where the row and column filters are identical.

Parameters:
subkernel the one-dimensional kernel to be used as row and column filter.

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

Destructor.


Member Function Documentation

template<class T>
separableKernel<T>& cvr::separableKernel< T >::apply ( const separableKernel< T > &  other,
T(*)(const T &)  function 
)

Applies a C-function to each element the other kernel and leaves the result here.

Parameters:
other the kernel with the source data
function a pointer to a C-function
Returns:
a reference to the actual kernel

template<class T>
separableKernel<T>& cvr::separableKernel< T >::apply ( const separableKernel< T > &  other,
T(*)(T)  function 
)

Applies a C-function to each element of the other kernel and leaves the result here.

Parameters:
other the source kernel
function a pointer to a C-function
Returns:
a reference to the actual kernel

template<class T>
separableKernel<T>& cvr::separableKernel< T >::apply ( T(*)(const T &)  function  ) 

Applies a C-function to each element of the kernel.

Parameters:
function a pointer to a C-function
Returns:
a reference to the actual kernel

template<class T>
separableKernel<T>& cvr::separableKernel< T >::apply ( T(*)(T)  function  ) 

Applies a C-function to each element of the kernel.

In the following example, kernel kernel is initialized with 4.0. After applying sqrt(), all elements of kernel are 2.0.

 separableKernel<float> kern(-2,2,4.0);
 kern.apply(sqrt);
Parameters:
function a pointer to a C-function
Returns:
a reference to the actual kernel

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

Copy from kernel of another type.

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

References cvr::separableKernel< T >::getColumnFilter(), cvr::separableKernel< T >::getNumberOfPairs(), cvr::separableKernel< T >::getRowFilter(), and cvr::separableKernel< T >::kernels_.

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

Clone member.

Returns:
a pointer to a copy of this instance

Implements cvr::container.

template<class T>
T cvr::separableKernel< T >::computeSumOfElements (  )  const

Returns the sum of the elements of the resulting 2D kernel.

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

Copy member.

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

template<class T>
const kernel1D<T>& cvr::separableKernel< T >::getColumnFilter ( const int  i  )  const [inline]

Return an unmodifiable column kernel.

Parameters:
i the index of the column filter. This value must be between 0 and getNumberOfPairs()

References cvr::separableKernel< T >::kernels_.

template<class T>
kernel1D<T>& cvr::separableKernel< T >::getColumnFilter ( const int  i  )  [inline]

Return a column-kernel.

Parameters:
i the index of the column filter. This value must be between 0 and getNumberOfPairs()

References cvr::separableKernel< T >::kernels_.

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

template<class T>
int cvr::separableKernel< T >::getNumberOfPairs (  )  const

Number of filter pairs.

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

template<class T>
const kernel1D<T>& cvr::separableKernel< T >::getRowFilter ( const int  i  )  const [inline]

Return an unmodifiable row kernel.

Parameters:
i the index of the row filter. This value must be between 0 and getNumberOfPairs()

References cvr::separableKernel< T >::kernels_.

template<class T>
kernel1D<T>& cvr::separableKernel< T >::getRowFilter ( const int  i  )  [inline]

Return a row-kernel.

Parameters:
i the index of the row filter. This value must be between 0 and getNumberOfPairs()

References cvr::separableKernel< T >::kernels_.

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

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

Mirror this kernel, i.e.

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

Returns:
a reference to this instance

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

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

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

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

template<class T>
separableKernel<T>& cvr::separableKernel< T >::multiply ( const T &  value  ) 

Multiply each 1D kernel with a constant value.

Parameters:
value the value to be multiplied with
Returns:
a reference to this object

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

Returns the name of this type.

Implements cvr::ioObject.

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

Return a new instance of a separable kernel.

Returns:
a pointer to a new instance

Implements cvr::container.

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

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

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

Read the object from the given ioHandler.

Reimplemented from cvr::ioObject.

template<class T>
bool cvr::separableKernel< T >::separate ( const kernel2D< T > &  k,
const double &  maxDev = 0.01 
)

Separate a 2D kernel into 1D kernels.

Try to separate the two dimensional kernel k. Stop the separation if the error between original and separated kernel is less than maxDev.

Parameters:
k the two dimensional filter to be separated
maxDev the maximal deviation per element to be achieved
Returns:
true if the separation succeeded or false otherwise.

template<class T>
void cvr::separableKernel< T >::setNorm ( const T &  newNorm  ) 

Set the norm of each individual 1D kernel to the given value.

Parameters:
newNorm the value to be used as norm
Returns:
a reference to this object

template<class T>
void cvr::separableKernel< T >::setNumberOfPairs ( const int  numPairs  ) 

Set the number of column/row 1D-filters.

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

Write the object in the given ioHandler.

Reimplemented from cvr::ioObject.


Member Data Documentation

template<class T>
std::vector< kernelPair > cvr::separableKernel< T >::kernels_ [protected]


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

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