Base for functions which calculate and apply 2D transformations. More...
#include <msm_aligner.h>
Public Member Functions | |
virtual | ~msm_aligner () |
virtual unsigned | size () const =0 |
Return number of parameters defining the transformation. | |
virtual vnl_vector< double > | inverse (const vnl_vector< double > &) const =0 |
Compute parameters for inverse transformation. | |
virtual void | apply_transform (const msm_points &points, const vnl_vector< double > &trans, msm_points &new_points) const =0 |
Apply the transformation to the given points. | |
virtual double | scale (const vnl_vector< double > &trans) const =0 |
Return scaling applied by the transform with given parameters. | |
virtual void | calc_transform_from_ref (const msm_points &ref_points, const msm_points &points2, vnl_vector< double > &trans) const =0 |
Estimate parameter which best map ref_points to points2. | |
virtual void | calc_transform (const msm_points &points1, const msm_points &points2, vnl_vector< double > &trans) const =0 |
Estimate parameter which best map points1 to points2. | |
virtual void | calc_transform_wt (const msm_points &points1, const msm_points &points2, const vnl_vector< double > &wts, vnl_vector< double > &trans) const =0 |
Estimate parameters which map points1 to points2 allowing for weights. | |
virtual void | calc_transform_wt_mat (const msm_points &points1, const msm_points &points2, const vcl_vector< msm_wt_mat_2d > &wt_mat, vnl_vector< double > &trans) const =0 |
Estimate parameters which map points allowing for anisotropic wts. | |
virtual void | transform_wt_mat (const vcl_vector< msm_wt_mat_2d > &wt_mat, const vnl_vector< double > &trans, vcl_vector< msm_wt_mat_2d > &new_wt_mat) const =0 |
Apply transform to weight matrices (ie ignore translation component). | |
virtual vnl_vector< double > | compose (const vnl_vector< double > &pose1, const vnl_vector< double > &pose2) const =0 |
Returns params of pose such that pose(x) = pose1(pose2(x)). | |
virtual void | normalise_shape (msm_points &points) const =0 |
Apply transform to generate points in some reference frame. | |
virtual void | align_set (const vcl_vector< msm_points > &points, msm_points &ref_mean_shape, vcl_vector< vnl_vector< double > > &pose_to_ref, vnl_vector< double > &average_pose) const =0 |
Find poses which align a set of points. | |
void | mean_of_transformed (const vcl_vector< msm_points > &points, const vcl_vector< vnl_vector< double > > &pose, msm_points &mean) const |
Compute mean of points[i] after transforming with pose[i]. | |
virtual vcl_string | is_a () const =0 |
Name of the class. | |
virtual msm_aligner * | clone () const =0 |
Create a copy on the heap and return base class pointer. | |
virtual void | print_summary (vcl_ostream &os) const |
Print class to os. | |
virtual void | b_write (vsl_b_ostream &bfs) const |
Save class to binary file stream. | |
virtual void | b_read (vsl_b_istream &bfs) |
Load class from binary file stream. | |
virtual void | config_from_stream (vcl_istream &is) |
Initialise from a text stream. | |
Static Public Member Functions | |
static vcl_auto_ptr< msm_aligner > | create_from_stream (vcl_istream &is) |
Create a concrete msm_aligner-derived object, from a text specification. |
Base for functions which calculate and apply 2D transformations.
Derived classes represent transformations, eg translation, similarity, affine. The parameters of the transformation are stored in a vector, arranged so that the zero vector corresponds to the identity transformation. Each class contains functions to apply the transformation, invert it and to estimate the best transform parameters to map one set of points to another.
Definition at line 25 of file msm_aligner.h.
virtual msm_aligner::~msm_aligner | ( | ) | [inline, virtual] |
Definition at line 29 of file msm_aligner.h.
virtual void msm_aligner::align_set | ( | const vcl_vector< msm_points > & | points, |
msm_points & | ref_mean_shape, | ||
vcl_vector< vnl_vector< double > > & | pose_to_ref, | ||
vnl_vector< double > & | average_pose | ||
) | const [pure virtual] |
Find poses which align a set of points.
On exit ref_mean_shape is the mean shape in the reference frame, pose_to_ref[i] maps points[i] into the reference frame (ie pose is the mapping from the reference frame to the target frames).
average_pose | Some estimate of the average mapping |
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual void msm_aligner::apply_transform | ( | const msm_points & | points, |
const vnl_vector< double > & | trans, | ||
msm_points & | new_points | ||
) | const [pure virtual] |
Apply the transformation to the given points.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
void msm_aligner::b_read | ( | vsl_b_istream & | bfs | ) | [virtual] |
Load class from binary file stream.
Definition at line 46 of file msm_aligner.cxx.
void msm_aligner::b_write | ( | vsl_b_ostream & | bfs | ) | const [virtual] |
Save class to binary file stream.
Definition at line 39 of file msm_aligner.cxx.
virtual void msm_aligner::calc_transform | ( | const msm_points & | points1, |
const msm_points & | points2, | ||
vnl_vector< double > & | trans | ||
) | const [pure virtual] |
Estimate parameter which best map points1 to points2.
Minimises ||points2-T(points1)||^2
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual void msm_aligner::calc_transform_from_ref | ( | const msm_points & | ref_points, |
const msm_points & | points2, | ||
vnl_vector< double > & | trans | ||
) | const [pure virtual] |
Estimate parameter which best map ref_points to points2.
Minimises ||points2-T(ref_points)||^2. Takes advantage of assumed properties of ref_points (eg CoG=origin, unit size etc) to perform efficiently.
When used with a shape model of form ref_points+Pb, where the modes P have certain orthogonality properties with respect to the ref shape, this can give the optimal transformation into a tangent plane, independent of the current parameters. In this case a one-shot method can be used to compute the optimal shape and pose parameters, rather than an iterative method which is required where the orthogonality properties do not hold, or where weights are considered.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual void msm_aligner::calc_transform_wt | ( | const msm_points & | points1, |
const msm_points & | points2, | ||
const vnl_vector< double > & | wts, | ||
vnl_vector< double > & | trans | ||
) | const [pure virtual] |
Estimate parameters which map points1 to points2 allowing for weights.
Minimises sum of weighted squares error in frame of pts2, ie sum w_i * ||p2_i - T(p1_i)||
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual void msm_aligner::calc_transform_wt_mat | ( | const msm_points & | points1, |
const msm_points & | points2, | ||
const vcl_vector< msm_wt_mat_2d > & | wt_mat, | ||
vnl_vector< double > & | trans | ||
) | const [pure virtual] |
Estimate parameters which map points allowing for anisotropic wts.
Errors on point i are weighted by wt_mat[i] in pts2 frame. ie error is sum (p2_i-T(p1_i)'*wt_mat[i]*(p2_i-T(p1_i)
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual msm_aligner* msm_aligner::clone | ( | ) | const [pure virtual] |
Create a copy on the heap and return base class pointer.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual vnl_vector<double> msm_aligner::compose | ( | const vnl_vector< double > & | pose1, |
const vnl_vector< double > & | pose2 | ||
) | const [pure virtual] |
Returns params of pose such that pose(x) = pose1(pose2(x)).
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
void msm_aligner::config_from_stream | ( | vcl_istream & | is | ) | [virtual] |
Initialise from a text stream.
The default implementation is for attribute-less normalisers, and throws if it finds any data in the stream.
Definition at line 70 of file msm_aligner.cxx.
vcl_auto_ptr< msm_aligner > msm_aligner::create_from_stream | ( | vcl_istream & | is | ) | [static] |
Create a concrete msm_aligner-derived object, from a text specification.
Definition at line 84 of file msm_aligner.cxx.
virtual vnl_vector<double> msm_aligner::inverse | ( | const vnl_vector< double > & | ) | const [pure virtual] |
Compute parameters for inverse transformation.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual vcl_string msm_aligner::is_a | ( | ) | const [pure virtual] |
Name of the class.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
void msm_aligner::mean_of_transformed | ( | const vcl_vector< msm_points > & | points, |
const vcl_vector< vnl_vector< double > > & | pose, | ||
msm_points & | mean | ||
) | const |
Compute mean of points[i] after transforming with pose[i].
Compute mean of points after transforming with pose.
Definition at line 14 of file msm_aligner.cxx.
virtual void msm_aligner::normalise_shape | ( | msm_points & | points | ) | const [pure virtual] |
Apply transform to generate points in some reference frame.
For instance, depending on transform, may translate so the centre of gravity is at the origin and scale to a unit size.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
void msm_aligner::print_summary | ( | vcl_ostream & | os | ) | const [virtual] |
Print class to os.
Definition at line 31 of file msm_aligner.cxx.
virtual double msm_aligner::scale | ( | const vnl_vector< double > & | trans | ) | const [pure virtual] |
Return scaling applied by the transform with given parameters.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual unsigned msm_aligner::size | ( | ) | const [pure virtual] |
Return number of parameters defining the transformation.
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.
virtual void msm_aligner::transform_wt_mat | ( | const vcl_vector< msm_wt_mat_2d > & | wt_mat, |
const vnl_vector< double > & | trans, | ||
vcl_vector< msm_wt_mat_2d > & | new_wt_mat | ||
) | const [pure virtual] |
Apply transform to weight matrices (ie ignore translation component).
Implemented in msm_similarity_aligner, msm_zoom_aligner, and msm_translation_aligner.