Image Component Library (ICL)
|
Utility structure that represents a 2D homography (implemented for float and double) More...
#include <Homography2D.h>
Public Types | |
enum | Algorithm { Simple, Advanced } |
Internally used algorithm type. More... | |
typedef FixedMatrix< T, 3, 3 > | Super |
super class typedef for shorter super-class references | |
Public Member Functions | |
GenericHomography2D () | |
Empty constructor. | |
GenericHomography2D (const utils::Point32f *pAs, const utils::Point32f *pBs, int n=4, Algorithm algo=Advanced) | |
Constructor from given two point sets of size n>=4. | |
utils::Point32f | apply (const utils::Point32f &p) const |
applies the homography | |
utils::Point32f | apply_int (const utils::Point32f &p) const |
applies the homography | |
Static Public Member Functions | |
static utils::Point32f | apply_homography (const FixedMatrix< float, 3, 3 > &H, const utils::Point32f &p) |
applies a given homography matrix | |
static utils::Point | apply_homography_int (const FixedMatrix< float, 3, 3 > &H, const utils::Point &p) |
applies a given homography matrix |
Utility structure that represents a 2D homography (implemented for float and double)
Basically, a 2D homography implements a transformation between 2 paralellograms Given a set of at least 4 points in parallellogram A and the same number of corresponding points in parallelogram B, the homography (affine 2D transformation between space A and space B is defined as follows:
must transform each point (given wrt. space A) to it's corresponding point . Please refer to Wikipedia or the class implementation for more details:
The Homography2D class provides two different algorithms: a faster simple one, and a slightly slower, but more elaborated one. The simple algorithm creates a simpler matrix whose last row becomes (0,0,1)^T. In some cases, this is enough, which is why, this algorithm is provided even though, it does not lead to perfect results.
The homography is used to transform a set of homogeneous 2D source points into a set of 2D destination points . Since we search for a linear transformation, This transformation H is modelled by a 3x3 matrix whose last element is fixed to 1. We call the rows of H X,Y,L, which leads to the targeted equation:
The most simple approach is to stack all and all horizontally which leads to the equation
Obviously, this can be solved using a standard pseudoinverse approach
This approach does somehow optimize the problem, but it does not really touch the last row of H. Therefore, the results of this simple approach are sometimes not good enough. Please continue with The Advanced Algorithm
In order to also fill the last row of H with optimal values, the originating problem must be reformulated in matrix notation in a different way:
Again, we start with
For a single (we call it a and the counter part b resp.), we always have two formulas, one for the x- and one for the y-component.
Decomposing H to its rows X,Y and L, this can be reformulated as
By multiplying with ( resp.), we get
These two equations can be expressed in a single huge matrix expression where M is a 2n by 8 matrix, and and r are 2n-dimensional row vectors. M and r are build as follows. For each input/output tuple , two rows of M are created using the following scheme:
The result vector r is just filled with the target values
Finally the matrix equation is evaluated with respect to h by
And h's elements are put back into the homography matrix H in a row-wise manner. Remember that The last elememt of H was set fixed to 1. Please note: Internally, the matrix equation is solved using an SVD (
typedef FixedMatrix<T,3,3> icl::math::GenericHomography2D< T >::Super |
super class typedef for shorter super-class references
enum icl::math::GenericHomography2D::Algorithm |
Internally used algorithm type.
Simple |
use the simple algorithm (
|
Advanced |
use the advanced algorithm (
|
icl::math::GenericHomography2D< T >::GenericHomography2D | ( | ) | [inline] |
Empty constructor.
icl::math::GenericHomography2D< T >::GenericHomography2D | ( | const utils::Point32f * | pAs, |
const utils::Point32f * | pBs, | ||
int | n = 4 , |
||
Algorithm | algo = Advanced |
||
) |
Constructor from given two point sets of size n>=4.
utils::Point32f icl::math::GenericHomography2D< T >::apply | ( | const utils::Point32f & | p | ) | const [inline] |
applies the homography
static utils::Point32f icl::math::GenericHomography2D< T >::apply_homography | ( | const FixedMatrix< float, 3, 3 > & | H, |
const utils::Point32f & | p | ||
) | [inline, static] |
applies a given homography matrix
static utils::Point icl::math::GenericHomography2D< T >::apply_homography_int | ( | const FixedMatrix< float, 3, 3 > & | H, |
const utils::Point & | p | ||
) | [inline, static] |
applies a given homography matrix
utils::Point32f icl::math::GenericHomography2D< T >::apply_int | ( | const utils::Point32f & | p | ) | const [inline] |
applies the homography