contrib/rpl/rgrl/rgrl_trans_homography2d.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_homography2d_h_
00002 #define rgrl_trans_homography2d_h_
00003 //:
00004 // \file
00005 // \author Charlene Tsai
00006 // \date   Oct 2004
00007 
00008 #include "rgrl_transformation.h"
00009 #include <vnl/vnl_matrix_fixed.h>
00010 #include <vnl/vnl_vector_fixed.h>
00011 #include <vcl_iosfwd.h>
00012 
00013 //: Represents a 2D homography transformation.
00014 //
00015 //  A transformation for x'=Hx. It is for 2D only.
00016 
00017 class rgrl_trans_homography2d
00018   : public rgrl_transformation
00019 {
00020  public:
00021   //: Initialize to the identity matrix
00022   rgrl_trans_homography2d();
00023 
00024   //: Constructor based on an initial transformation and covar estimate
00025   //
00026   rgrl_trans_homography2d( vnl_matrix<double> const& H,
00027                            vnl_matrix<double> const& covar );
00028 
00029   //: Constructor based on an initial transformation and unknown covar
00030   //
00031   //  The  covariance matrix is a zero matrix.
00032   rgrl_trans_homography2d( vnl_matrix<double> const& H );
00033 
00034   //: Construct a centered transform.
00035   //
00036   rgrl_trans_homography2d( vnl_matrix<double> const& H,
00037                            vnl_matrix<double> const& covar,
00038                            vnl_vector<double> const& from_centre,
00039                            vnl_vector<double> const& to_centre );
00040 
00041   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p  ) const;
00042 
00043   //: Inverse map using pseudo-inverse of H_.
00044   void inv_map( const vnl_vector<double>& to,
00045                 vnl_vector<double>& from ) const;
00046 
00047   //:  Inverse map with an initial guess
00048   void inv_map( const vnl_vector<double>& to,
00049                 bool initialize_next,
00050                 const vnl_vector<double>& to_delta,
00051                 vnl_vector<double>& from,
00052                 vnl_vector<double>& from_next_est) const;
00053 
00054   //: is this an invertible transformation?
00055   bool is_invertible() const { return true; }
00056 
00057   //: Return an inverse transformation of the uncentered transform
00058   rgrl_transformation_sptr inverse_transform() const;
00059 
00060   //: Compute jacobian w.r.t. location
00061   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00062 
00063   //: Return the jacobian of the transform. This is a 2x3 matrix
00064   vnl_matrix_fixed<double,2,3> homo_jacobian( vnl_vector_fixed<double,2> const& from_loc ) const;
00065 
00066   //:  transform the transformation for images of different resolution
00067   rgrl_transformation_sptr scale_by( double scale ) const;
00068 
00069   //: log of determinant of the covariance
00070   virtual double
00071   log_det_covar() const
00072   { return log_det_covar_deficient( 8 ); }
00073 
00074   // Defines type-related functions
00075   rgrl_type_macro( rgrl_trans_homography2d, rgrl_transformation );
00076 
00077   // for output UNCENTERED transformation, with the origin as the center.
00078   void write(vcl_ostream& os ) const;
00079 
00080   // for input
00081   bool read(vcl_istream& is );
00082 
00083   //: make a clone copy
00084   rgrl_transformation_sptr clone() const;
00085 
00086   //: The scaling and rotation component of the transform
00087   vnl_matrix_fixed<double, 3, 3> H() const;
00088 
00089   // uncenter H matrix
00090   vnl_matrix_fixed<double,3,3> uncenter_H_matrix() const;
00091 
00092  protected:
00093   void map_loc( vnl_vector<double> const& from,
00094                 vnl_vector<double>      & to  ) const;
00095 
00096   void map_dir( vnl_vector<double> const& from_loc,
00097                 vnl_vector<double> const& from_dir,
00098                 vnl_vector<double>      & to_dir  ) const;
00099 
00100  private:
00101   vnl_matrix_fixed<double,3,3> H_;
00102   vnl_vector_fixed<double,2>   from_centre_;
00103   vnl_vector_fixed<double,2>   to_centre_;
00104 };
00105 
00106 #endif