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