latest version v1.9 - last update 10 Apr 2010 |
Separable Kernel. More...
#include <ltiLinearKernels.h>
Public Member Functions | |
sepKernel () | |
sepKernel (const sepKernel &other) | |
sepKernel (const int &from, const int &to, const T &iniValue=T()) | |
sepKernel (const kernel1D< T > &subkernel) | |
virtual | ~sepKernel () |
sepKernel & | copy (const sepKernel &other) |
const char * | getTypeName () const |
virtual mathObject * | clone () const |
template<class U > | |
sepKernel & | castFrom (const sepKernel< 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 > & | getColFilter (const int &i) |
const kernel1D< T > & | getRowFilter (const int &i) const |
const kernel1D< T > & | getColFilter (const int &i) const |
void | denormalize () |
sepKernel< T > & | multiply (const T &value) |
void | setNorm (const T &newNorm) |
T | sumOfElements () const |
sepKernel< T > & | mirror (const sepKernel< T > &other) |
sepKernel< T > & | mirror () |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
virtual bool | read (ioHandler &handler, const bool complete=true) |
Apply Methods | |
sepKernel< T > & | apply (T(*function)(T)) |
sepKernel< T > & | apply (T(*function)(const T &)) |
sepKernel< T > & | apply (const sepKernel< T > &other, T(*function)(T)) |
sepKernel< T > & | apply (const sepKernel< T > &other, T(*function)(const T &)) |
Protected Attributes | |
std::vector< kernel1D< T > > | rowKernels |
std::vector< kernel1D< T > > | colKernels |
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 sepKernel with a lti::channel, you will need a sepKernel<channel::value_type> or sepKernel<float>.
If you instantiate a sepKernel of a fixed point type, like sepKernel<int> or sepKernel<ubyte>, you also need to consider the "norm" of the kernel (see lti::sepKernel<T>::getNorm() and lti::sepKernel<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 sepKernel<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 lti::typeInfo)
lti::sepKernel< T >::sepKernel | ( | ) |
default constructor
lti::sepKernel< T >::sepKernel | ( | const sepKernel< T > & | other | ) |
copy constructor
other | the kernel to be copied. |
lti::sepKernel< T >::sepKernel | ( | const int & | from, | |
const int & | to, | |||
const T & | iniValue = T() | |||
) |
lti::sepKernel< T >::sepKernel | ( | const kernel1D< T > & | subkernel | ) |
virtual lti::sepKernel< T >::~sepKernel | ( | ) | [virtual] |
destructor
sepKernel<T>& lti::sepKernel< T >::apply | ( | const sepKernel< T > & | other, | |
T(*)(const T &) | function | |||
) |
applies a C-function to each element the other kernel and leaves the result here.
other | the kernel with the source data | |
function | a pointer to a C-function |
sepKernel<T>& lti::sepKernel< T >::apply | ( | const sepKernel< T > & | other, | |
T(*)(T) | function | |||
) |
applies a C-function to each element of the other kernel and leaves the result here.
other | the source kernel | |
function | a pointer to a C-function |
sepKernel<T>& lti::sepKernel< T >::apply | ( | T(*)(const T &) | function | ) |
applies a C-function to each element of the kernel.
function | a pointer to a C-function |
sepKernel<T>& lti::sepKernel< 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.
function | a pointer to a C-function |
sepKernel& lti::sepKernel< T >::castFrom | ( | const sepKernel< U > & | other | ) | [inline] |
copy from kernel of another type
other | a separable kernel of another type |
virtual mathObject* lti::sepKernel< T >::clone | ( | ) | const [inline, virtual] |
sepKernel& lti::sepKernel< T >::copy | ( | const sepKernel< T > & | other | ) |
copy member
other | the kernel to be copied. |
Reimplemented from lti::ioObject.
void lti::sepKernel< T >::denormalize | ( | ) |
denormalize divide all elements by norm and set the norm to 1!
const kernel1D<T>& lti::sepKernel< T >::getColFilter | ( | const int & | i | ) | const [inline] |
return an unmodifiable column kernel
i | the index of the column filter. This value must be between 0 and getNumberOfPairs() |
kernel1D<T>& lti::sepKernel< T >::getColFilter | ( | const int & | i | ) | [inline] |
return a column-kernel
i | the index of the column filter. This value must be between 0 and getNumberOfPairs() |
Referenced by lti::sepKernel< float >::castFrom().
int lti::sepKernel< T >::getNumberOfPairs | ( | ) | const |
number of filter pairs
Referenced by lti::sepKernel< float >::castFrom().
const kernel1D<T>& lti::sepKernel< T >::getRowFilter | ( | const int & | i | ) | const [inline] |
return an unmodifiable row kernel
i | the index of the row filter. This value must be between 0 and getNumberOfPairs() |
kernel1D<T>& lti::sepKernel< T >::getRowFilter | ( | const int & | i | ) | [inline] |
return a row-kernel
i | the index of the row filter. This value must be between 0 and getNumberOfPairs() |
Referenced by lti::sepKernel< float >::castFrom().
const char* lti::sepKernel< T >::getTypeName | ( | void | ) | const [inline, virtual] |
returns name of this type ("sepKernel")
Reimplemented from lti::mathObject.
sepKernel<T>& lti::sepKernel< T >::mirror | ( | ) |
Mirror this kernel, i.e.
at(y,x) = at(-y,-x);
sepKernel<T>& lti::sepKernel< T >::mirror | ( | const sepKernel< T > & | other | ) |
Mirror the other kernel and leave the result here, i.e.
at(y,x) = other.at(-y,-x);
other | the kernel to be copied and then mirrored |
sepKernel<T>& lti::sepKernel< T >::multiply | ( | const T & | value | ) |
multiply each 1D kernel with a constant value
value | the value to be multiplied with |
virtual bool lti::sepKernel< T >::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
read the object from the given ioHandler
Reimplemented from lti::mathObject.
bool lti::sepKernel< 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
.
k | the two dimensional filter to be separated | |
maxDev | the maximal deviation per element to be achieved |
void lti::sepKernel< T >::setNorm | ( | const T & | newNorm | ) |
set the norm of each individual 1D kernel to the given value
newNorm | the value to be used as norm |
void lti::sepKernel< T >::setNumberOfPairs | ( | const int & | numPairs | ) |
set the number of column/row 1D-filters
T lti::sepKernel< T >::sumOfElements | ( | ) | const |
returns the sum of the elements of the resulting 2D kernel
virtual bool lti::sepKernel< T >::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
write the object in the given ioHandler
Reimplemented from lti::mathObject.
std::vector< kernel1D<T> > lti::sepKernel< T >::colKernels [protected] |
list of one-dimensional column kernels
Referenced by lti::sepKernel< float >::castFrom(), and lti::sepKernel< float >::getColFilter().
std::vector< kernel1D<T> > lti::sepKernel< T >::rowKernels [protected] |
list of one-dimensional row kernels
Referenced by lti::sepKernel< float >::castFrom(), and lti::sepKernel< float >::getRowFilter().