last update 20 Sep 2009 |
#include <cvrSeparableKernel.h>
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 () |
separableKernel & | copy (const separableKernel &other) |
virtual const std::string & | name () const |
virtual separableKernel * | clone () const |
virtual separableKernel * | newInstance () const |
template<class U > | |
separableKernel & | castFrom (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) |
T | 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< kernelPair > | kernels_ |
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)
cvr::separableKernel< T >::separableKernel | ( | ) |
Default constructor.
cvr::separableKernel< T >::separableKernel | ( | const separableKernel< T > & | other | ) |
Copy constructor.
other | the kernel to be copied. |
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.
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 |
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.
subkernel | the one-dimensional kernel to be used as row and column filter. |
virtual cvr::separableKernel< T >::~separableKernel | ( | ) | [virtual] |
Destructor.
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.
other | the kernel with the source data | |
function | a pointer to a C-function |
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.
other | the source kernel | |
function | a pointer to a C-function |
separableKernel<T>& cvr::separableKernel< T >::apply | ( | T(*)(const T &) | function | ) |
Applies a C-function to each element of the kernel.
function | a pointer to a C-function |
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);
function | a pointer to a C-function |
separableKernel& cvr::separableKernel< T >::castFrom | ( | const separableKernel< U > & | other | ) | [inline] |
Copy from kernel of another type.
other | a separable kernel of another type |
References cvr::separableKernel< T >::getColumnFilter(), cvr::separableKernel< T >::getNumberOfPairs(), cvr::separableKernel< T >::getRowFilter(), and cvr::separableKernel< T >::kernels_.
virtual separableKernel* cvr::separableKernel< T >::clone | ( | ) | const [virtual] |
T cvr::separableKernel< T >::computeSumOfElements | ( | ) | const |
Returns the sum of the elements of the resulting 2D kernel.
separableKernel& cvr::separableKernel< T >::copy | ( | const separableKernel< T > & | other | ) |
Copy member.
other | the kernel to be copied. |
const kernel1D<T>& cvr::separableKernel< T >::getColumnFilter | ( | 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() |
References cvr::separableKernel< T >::kernels_.
kernel1D<T>& cvr::separableKernel< T >::getColumnFilter | ( | const int | i | ) | [inline] |
Return a column-kernel.
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().
int cvr::separableKernel< T >::getNumberOfPairs | ( | ) | const |
const kernel1D<T>& cvr::separableKernel< 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() |
References cvr::separableKernel< T >::kernels_.
kernel1D<T>& cvr::separableKernel< 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() |
References cvr::separableKernel< T >::kernels_.
Referenced by cvr::separableKernel< T >::castFrom().
separableKernel<T>& cvr::separableKernel< T >::mirror | ( | ) |
Mirror this kernel, i.e.
at(y,x) = at(-y,-x);
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);
other | the kernel to be copied and then mirrored |
separableKernel<T>& cvr::separableKernel< T >::multiply | ( | const T & | value | ) |
Multiply each 1D kernel with a constant value.
value | the value to be multiplied with |
virtual const std::string& cvr::separableKernel< T >::name | ( | ) | const [virtual] |
virtual separableKernel* cvr::separableKernel< T >::newInstance | ( | ) | const [virtual] |
Return a new instance of a separable kernel.
Implements cvr::container.
void cvr::separableKernel< T >::normalize | ( | ) |
Normalize divides all elements by norm and set the norm to 1!
virtual bool cvr::separableKernel< T >::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
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.
k | the two dimensional filter to be separated | |
maxDev | the maximal deviation per element to be achieved |
void cvr::separableKernel< 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 cvr::separableKernel< T >::setNumberOfPairs | ( | const int | numPairs | ) |
Set the number of column/row 1D-filters.
virtual bool cvr::separableKernel< T >::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
std::vector< kernelPair > cvr::separableKernel< T >::kernels_ [protected] |
List of one-dimensional row kernels.
Referenced by cvr::separableKernel< T >::castFrom(), cvr::separableKernel< T >::getColumnFilter(), and cvr::separableKernel< T >::getRowFilter().