1 #ifndef rgrl_trans_homography2d_h_ 2 #define rgrl_trans_homography2d_h_ 3 //: 4 // \file 5 // \author Charlene Tsai 6 // \date Oct 2004 7 8 #include <iostream> 9 #include <iosfwd> 10 #include "rgrl_transformation.h" 11 #include <vnl/vnl_matrix_fixed.h> 12 #include <vnl/vnl_vector_fixed.h> 13 #ifdef _MSC_VER 14 # include <vcl_msvc_warnings.h> 15 #endif 16 17 //: Represents a 2D homography transformation. 18 // 19 // A transformation for x'=Hx. It is for 2D only. 20 21 class rgrl_trans_homography2d 22 : public rgrl_transformation 23 { 24 public: 25 //: Initialize to the identity matrix 26 rgrl_trans_homography2d(); 27 28 //: Constructor based on an initial transformation and covar estimate 29 // 30 rgrl_trans_homography2d( vnl_matrix<double> const& H, 31 vnl_matrix<double> const& covar ); 32 33 //: Constructor based on an initial transformation and unknown covar 34 // 35 // The covariance matrix is a zero matrix. 36 rgrl_trans_homography2d( vnl_matrix<double> const& H ); 37 38 //: Construct a centered transform. 39 // 40 rgrl_trans_homography2d( vnl_matrix<double> const& H, 41 vnl_matrix<double> const& covar, 42 vnl_vector<double> const& from_centre, 43 vnl_vector<double> const& to_centre ); 44 45 vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p ) const override; 46 47 //: Inverse map using pseudo-inverse of H_. 48 void inv_map( const vnl_vector<double>& to, 49 vnl_vector<double>& from ) const override; 50 51 //: Inverse map with an initial guess 52 void inv_map( const vnl_vector<double>& to, 53 bool initialize_next, 54 const vnl_vector<double>& to_delta, 55 vnl_vector<double>& from, 56 vnl_vector<double>& from_next_est) const override; 57 58 //: is this an invertible transformation? is_invertible()59 bool is_invertible() const override { return true; } 60 61 //: Return an inverse transformation of the uncentered transform 62 rgrl_transformation_sptr inverse_transform() const override; 63 64 //: Compute jacobian w.r.t. location 65 void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const override; 66 67 //: Return the jacobian of the transform. This is a 2x3 matrix 68 vnl_matrix_fixed<double,2,3> homo_jacobian( vnl_vector_fixed<double,2> const& from_loc ) const; 69 70 //: transform the transformation for images of different resolution 71 rgrl_transformation_sptr scale_by( double scale ) const override; 72 73 //: log of determinant of the covariance 74 double log_det_covar()75 log_det_covar() const override 76 { return log_det_covar_deficient( 8 ); } 77 78 // Defines type-related functions 79 rgrl_type_macro( rgrl_trans_homography2d, rgrl_transformation ); 80 81 // for output UNCENTERED transformation, with the origin as the center. 82 void write(std::ostream& os ) const override; 83 84 // for input 85 bool read(std::istream& is ) override; 86 87 //: make a clone copy 88 rgrl_transformation_sptr clone() const override; 89 90 //: The scaling and rotation component of the transform 91 vnl_matrix_fixed<double, 3, 3> H() const; 92 93 // uncenter H matrix 94 vnl_matrix_fixed<double,3,3> uncenter_H_matrix() const; 95 96 protected: 97 void map_loc( vnl_vector<double> const& from, 98 vnl_vector<double> & to ) const override; 99 100 void map_dir( vnl_vector<double> const& from_loc, 101 vnl_vector<double> const& from_dir, 102 vnl_vector<double> & to_dir ) const override; 103 104 private: 105 vnl_matrix_fixed<double,3,3> H_; 106 vnl_vector_fixed<double,2> from_centre_; 107 vnl_vector_fixed<double,2> to_centre_; 108 }; 109 110 #endif 111