latest version v1.9 - last update 10 Apr 2010 |
This functor implements an generic geometric transform based on a homogeneous matrix, which is able to represent rotations, translations scalings and all other possibilites of homographies. More...
#include <ltiGeometricTransform.h>
Classes | |
struct | fastMatrix |
Structure to avoid the use of the access operator of matrices. More... | |
class | parameters |
The parameters for the class geometricTransform. More... | |
Public Member Functions | |
geometricTransform () | |
geometricTransform (const parameters &par) | |
geometricTransform (const geometricTransform &other) | |
virtual | ~geometricTransform () |
virtual const char * | getTypeName () const |
geometricTransform & | copy (const geometricTransform &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
virtual bool | updateParameters () |
Apply methods for points and point lists | |
template<class T > | |
bool | apply (tpoint< T > &srcdest) const |
template<class T > | |
bool | apply (const tpoint< T > &src, tpoint< T > &dest) const |
template<class T > | |
bool | apply (tpointList< T > &srcdest) const |
template<class T > | |
bool | apply (const tpointList< T > &src, tpointList< T > &dest) const |
Apply methods for matrices | |
template<class T > | |
bool | apply (matrix< T > &srcdest) const |
template<class T > | |
bool | apply (const matrix< T > &src, matrix< T > &dest, point &offset) const |
template<class T > | |
bool | apply (const matrix< T > &src, matrix< T > &dest) const |
Shortcuts for usual transformations. | |
// Usual parameters lti::geometricTransform::parameters geoPar; geoPar.keepDimensions = true; geoPar.boundaryType = lti::Mirror; // Create geometric transformation object lti::geometricTransform geoTrans(geoPar); // images lti::image img(256,256,lti::Black),res; // initialize your image with something (img.getRow(img.rows()/2)).fill(lti::Red); // Rotate an image using shortcuts and default interpolator geoTrans.rotate(img,res,45*Pi/180); // rotate 45 degrees | |
template<class T > | |
bool | scale (const matrix< T > &src, matrix< T > &dest, const tpoint< float > &factor) |
template<class T > | |
bool | scale (matrix< T > &srcdest, const tpoint< float > &factor) |
template<class T > | |
bool | rotate (const matrix< T > &src, matrix< T > &dest, const double &angle, const point ¢er=point(std::numeric_limits< int >::max(), std::numeric_limits< int >::max())) |
template<class T > | |
bool | rotate (matrix< T > &srcdest, const double &angle, const point ¢er=point(std::numeric_limits< int >::max(), std::numeric_limits< int >::max())) |
Protected Member Functions | |
template<class value_type > | |
void | transf (const tpoint< value_type > &src, tpoint< value_type > &dest, const fastMatrix &m) const |
| |
interpolatorCollection< double > | dcollect |
interpolatorCollection< float > | fcollect |
interpolatorCollection< int > | icollect |
interpolatorCollection< ubyte > | bcollect |
interpolatorCollection< rgbPixel > | ccollect |
const interpolatorCollection < double > & | getCollection (double &a) const |
const interpolatorCollection < float > & | getCollection (float &a) const |
const interpolatorCollection < int > & | getCollection (int &a) const |
const interpolatorCollection < ubyte > & | getCollection (ubyte &a) const |
const interpolatorCollection < rgbPixel > & | getCollection (rgbPixel &a) const |
This functor implements an generic geometric transform based on a homogeneous matrix, which is able to represent rotations, translations scalings and all other possibilites of homographies.
You can use your own matrix to generate a special geometric transformation, or you can use the member functions of the parameters class to generate the matrix and vectors for a given translation, rotation and scaling.
You can use all the three functions in arbitrary order and number to build your transform matrix sequentially.
With the invert()
member of the parameters class you can invert the matrix for the reverse transformation. The speed in general only depends on the size of the image or the size of the pointList.
Please note that even if the transformation can have a 3D nature (4x4 homogeneous matrix) and you can turn, shift or scale the image plane in any of the three coordinates, the input image is always a 2D object with z-coordinate zero. A typical error is trying to apply the inverse transformation matrix to reconstruct a 3D rotation: this cannot work because of the missing third coordinate for each pixel.
There are also a few specialized functors to achieve isolated transformation tasks in a much faster way. A derived class also restricts the transformation to a similarity transformation (see lti::similarityTransform2D).
lti::geometricTransform::geometricTransform | ( | ) |
Default constructor.
lti::geometricTransform::geometricTransform | ( | const parameters & | par | ) |
Default constructor with parameters object.
lti::geometricTransform::geometricTransform | ( | const geometricTransform & | other | ) |
Copy constructor.
other | the object to be copied |
virtual lti::geometricTransform::~geometricTransform | ( | ) | [virtual] |
Destructor.
bool lti::geometricTransform::apply | ( | const matrix< T > & | src, | |
matrix< T > & | dest, | |||
point & | offset | |||
) | const [inline] |
Applies the geometric transformation on the given parameter.
The transformation is applied on each point of the matrix.
src | matrix with the source data. | |
dest | the result will be left here. | |
offset | if you specified parameters::keepDimensions as false, then this is the offset added to each pixel transformation to obtain the results in a positive range. It is usefull if you also transform some points and want to obtain their value in the destination image. |
References lti::BicubicInterpolator, lti::BiquadraticInterpolator, getCollection(), getParameters(), and lti::NearestNeighborInterpolator.
bool lti::geometricTransform::apply | ( | matrix< T > & | srcdest | ) | const [inline] |
Applies the geometric transformation on the given parameter.
The transformation is applied on each point of the matrix.
srcdest | matix with the source data. The result will be left here too. |
References apply(), and lti::genericMatrix< T >::detach().
bool lti::geometricTransform::apply | ( | const tpointList< T > & | src, | |
tpointList< T > & | dest | |||
) | const [inline] |
Applies the geometric transformation on the given parameter.
The transformation is applied on each point of the list.
src | pointList with the source data. | |
dest | pointList where the result will be left. |
References lti::tpointList< T >::begin(), lti::tpointList< T >::clear(), lti::tpointList< T >::end(), getParameters(), lti::tpointList< T >::push_back(), and transf().
bool lti::geometricTransform::apply | ( | tpointList< T > & | srcdest | ) | const [inline] |
Applies the geometric transformation on the given parameter.
The transformation is applied on each point of the list.
srcdest | pointList with the source data. The result will be left here too. |
References lti::tpointList< T >::begin(), lti::tpointList< T >::end(), getParameters(), and transf().
bool lti::geometricTransform::apply | ( | const tpoint< T > & | src, | |
tpoint< T > & | dest | |||
) | const [inline] |
Apply the geometric transformation on src point and leave the result on dest.
src | point with the source data. | |
dest | point where the result will be left. |
References getParameters(), and transf().
bool lti::geometricTransform::apply | ( | tpoint< T > & | srcdest | ) | const [inline] |
virtual functor* lti::geometricTransform::clone | ( | ) | const [virtual] |
Returns a pointer to a clone of this functor.
Implements lti::functor.
geometricTransform& lti::geometricTransform::copy | ( | const geometricTransform & | other | ) |
Copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
const interpolatorCollection<rgbPixel>& lti::geometricTransform::getCollection | ( | rgbPixel & | a | ) | const [inline, protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
References ccollect.
const interpolatorCollection<ubyte>& lti::geometricTransform::getCollection | ( | ubyte & | a | ) | const [inline, protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
References bcollect.
const interpolatorCollection<int>& lti::geometricTransform::getCollection | ( | int & | a | ) | const [inline, protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
References icollect.
const interpolatorCollection<float>& lti::geometricTransform::getCollection | ( | float & | a | ) | const [inline, protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
References fcollect.
const interpolatorCollection<double>& lti::geometricTransform::getCollection | ( | double & | a | ) | const [inline, protected] |
const parameters& lti::geometricTransform::getParameters | ( | ) | const |
Returns used parameters.
Reimplemented from lti::modifier.
virtual const char* lti::geometricTransform::getTypeName | ( | ) | const [virtual] |
Returns the name of this type ("geometricTransform").
Reimplemented from lti::modifier.
bool lti::geometricTransform::rotate | ( | matrix< T > & | srcdest, | |
const double & | angle, | |||
const point & | center = point(std::numeric_limits<int>::max(), std::numeric_limits<int>::max()) | |||
) | [inline] |
Rotate the image on place.
srcdest | matrix with source data and where the result will be left | |
angle | angle in radians to rotate the image | |
center | rotation point (takes effect only if keepDimensions in the parameters is set to true). The default value ensures rotation on the image center. |
References lti::genericMatrix< T >::detach(), and rotate().
bool lti::geometricTransform::rotate | ( | const matrix< T > & | src, | |
matrix< T > & | dest, | |||
const double & | angle, | |||
const point & | center = point(std::numeric_limits<int>::max(), std::numeric_limits<int>::max()) | |||
) | [inline] |
Rotate the src image on copy.
src | source image | |
dest | matrix where the result will be left | |
angle | angle in radians to rotate the image | |
center | rotation point (takes effect only if keepDimensions in the parameters is set to true). The default value ensures rotation on the image center. |
References apply(), lti::genericMatrix< T >::columns(), getParameters(), lti::max(), lti::genericMatrix< T >::rows(), lti::functor::setParameters(), lti::tpoint3D< T >::x, lti::tpoint3D< T >::y, and lti::tpoint3D< T >::z.
Referenced by rotate().
bool lti::geometricTransform::scale | ( | matrix< T > & | srcdest, | |
const tpoint< float > & | factor | |||
) | [inline] |
Scale the srcdest image on-place.
You usually want to set parameters::keepDimensions to false when using this method.
srcdest | source image. The result will be left here too. | |
factor | point containing the scaling factor for x and y coordinates |
References lti::genericMatrix< T >::detach(), and scale().
bool lti::geometricTransform::scale | ( | const matrix< T > & | src, | |
matrix< T > & | dest, | |||
const tpoint< float > & | factor | |||
) | [inline] |
Scale the src image on copy.
You usually want to set parameters::keepDimensions to false when using this method.
src | source image | |
dest | matrix where the result will be left | |
factor | point containing the scaling factor for x and y coordinates |
References apply(), getParameters(), and lti::functor::setParameters().
Referenced by scale().
void lti::geometricTransform::transf | ( | const tpoint< value_type > & | src, | |
tpoint< value_type > & | dest, | |||
const fastMatrix & | m | |||
) | const [inline, protected] |
Transform 2D point.
Uses the given "fastMatrix" to transform the source point into the destination point.
References lti::condRoundCastTo(), lti::geometricTransform::fastMatrix::m00, lti::tpoint< T >::x, and lti::tpoint< T >::y.
Referenced by apply().
virtual bool lti::geometricTransform::updateParameters | ( | ) | [virtual] |
Set parameters.
Reimplemented from lti::functor.
interpolatorCollection<ubyte> lti::geometricTransform::bcollect [protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
Referenced by getCollection().
interpolatorCollection<rgbPixel> lti::geometricTransform::ccollect [protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
Referenced by getCollection().
interpolatorCollection<double> lti::geometricTransform::dcollect [protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
Referenced by getCollection().
interpolatorCollection<float> lti::geometricTransform::fcollect [protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
Referenced by getCollection().
interpolatorCollection<int> lti::geometricTransform::icollect [protected] |
Some attributes with the interpolators to save the creation time in the apply methods.
Referenced by getCollection().