contrib/mul/msm/msm_translation_aligner.h
Go to the documentation of this file.
00001 #ifndef msm_translation_aligner_h_
00002 #define msm_translation_aligner_h_
00003 //:
00004 // \file
00005 // \author Tim Cootes
00006 // \brief Calculate and apply 2D translations
00007 
00008 #include <msm/msm_aligner.h>
00009 
00010 class mbl_read_props_type;
00011 
00012 //: Calculate and apply 2D translations
00013 //  Translation encoded as (tx,ty).
00014 class msm_translation_aligner : public msm_aligner
00015 {
00016  public:
00017 
00018   virtual ~msm_translation_aligner() {}
00019 
00020   //: Return number of parameters defining the transformation
00021   virtual unsigned size() const { return 2; }
00022 
00023   //: Compute parameters for inverse transformation
00024   virtual vnl_vector<double> inverse(const vnl_vector<double>&) const;
00025 
00026   //: Apply the transformation to the given points
00027   virtual void apply_transform(const msm_points& points,
00028                                const vnl_vector<double>& trans,
00029                                msm_points& new_points) const;
00030 
00031   //: Return scaling applied by the transform with given parameters.
00032   virtual double scale(const vnl_vector<double>& trans) const;
00033 
00034   //: Estimate parameter which best map ref_points to points2
00035   //  Minimises ||points2-T(ref_points)||^2.
00036   //  Takes advantage of assumed properties of ref_points (eg CoG=origin,
00037   //  unit size etc) to perform efficiently.
00038   //
00039   //  When used with a shape model of form ref_points+Pb, where the modes P
00040   //  have certain orthogonality properties with respect to the ref shape,
00041   //  this can give the optimal transformation into a tangent plane, independent
00042   //  of the current parameters.  In this case a one-shot method can be used
00043   //  to compute the optimal shape and pose parameters, rather than an iterative
00044   //  method which is required where the orthogonality properties do not hold,
00045   //  or where weights are considered.
00046   virtual void calc_transform_from_ref(const msm_points& ref_points,
00047                                        const msm_points& points2,
00048                                        vnl_vector<double>& trans) const;
00049 
00050   //: Estimate parameter which best map points1 to points2
00051   //  Minimises ||points2-T(points1)||^2
00052   virtual void calc_transform(const msm_points& points1,
00053                               const msm_points& points2,
00054                               vnl_vector<double>& trans) const;
00055 
00056   //: Estimate parameters which map points1 to points2 allowing for weights
00057   //  Minimises sum of weighted squares error in frame of pts2,
00058   //  ie sum w_i * ||p2_i - T(p1_i)||
00059   virtual void calc_transform_wt(const msm_points& points1,
00060                                  const msm_points& points2,
00061                                  const vnl_vector<double>& wts,
00062                                  vnl_vector<double>& trans) const;
00063 
00064   //: Estimate parameters which map points allowing for anisotropic wts
00065   //  Errors on point i are weighted by wt_mat[i] in pts2 frame.
00066   //  i.e. error is sum (p2_i-T(p1_i)'*wt_mat[i]*(p2_i-T(p1_i)
00067   virtual void calc_transform_wt_mat(const msm_points& points1,
00068                                      const msm_points& points2,
00069                                      const vcl_vector<msm_wt_mat_2d>& wt_mat,
00070                                      vnl_vector<double>& trans) const;
00071 
00072   //: Apply transform to weight matrices (ie ignore translation component)
00073   virtual void transform_wt_mat(const vcl_vector<msm_wt_mat_2d>& wt_mat,
00074                                 const vnl_vector<double>& trans,
00075                                 vcl_vector<msm_wt_mat_2d>& new_wt_mat) const;
00076 
00077   //: Returns params of pose such that pose(x) = pose1(pose2(x))
00078   virtual vnl_vector<double> compose(const vnl_vector<double>& pose1,
00079                                      const vnl_vector<double>& pose2) const;
00080 
00081   //: Apply transform to generate points in reference frame
00082   //  Translate so that the centre of gravity is at the origin
00083   //  and scale to a unit size (points.vector().magnitude()==1)
00084   virtual void normalise_shape(msm_points& points) const;
00085 
00086   //: Find poses which align a set of points
00087   //  On exit ref_mean_shape is the mean shape in the reference
00088   //  frame, pose_to_ref[i] maps points[i] into the reference
00089   //  frame (ie pose is the mapping from the reference frame to
00090   //  the target frames).
00091   // \param average_pose Some estimate of the average mapping
00092   virtual void align_set(const vcl_vector<msm_points>& points,
00093                          msm_points& ref_mean_shape,
00094                          vcl_vector<vnl_vector<double> >& pose_to_ref,
00095                          vnl_vector<double>& average_pose) const;
00096 
00097   //: Name of the class
00098   virtual vcl_string is_a() const;
00099 
00100   //: Create a copy on the heap and return base class pointer
00101   virtual msm_aligner* clone() const;
00102 };
00103 
00104 #endif // msm_translation_aligner_h_