contrib/rpl/rgrl/rgrl_trans_rad_dis_homo2d.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_rad_dis_homo2d_h_
00002 #define rgrl_trans_rad_dis_homo2d_h_
00003 //:
00004 // \file
00005 // \author Gehua Yang
00006 // \date   Feb 2005
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 with radial lens distortion
00014 //
00015 //  From image Distortion:
00016 //    Xu = (1+k1*R^2) Xd
00017 //  To image Distortion
00018 //    Yd = (1+k1*R^2) Yu
00019 //  Homography transformation
00020 //    Y=H(X)
00021 //
00022 // NOTE: everything is in 2D non-homogeneous coordinates,
00023 //       therefore it is not linear
00024 
00025 class rgrl_trans_rad_dis_homo2d
00026   : public rgrl_transformation
00027 {
00028  public:
00029   //: Initialize to the identity matrix
00030   rgrl_trans_rad_dis_homo2d();
00031 
00032   //: Constructor based on an initial transformation and covar estimate
00033   //
00034   //rgrl_trans_rad_dis_homo2d( vnl_matrix<double> const& H,
00035   //                           double k1_from,
00036   //                           double k1_to,
00037   //                           vnl_matrix<double> const& covar );
00038 
00039   //: Constructor based on an initial transformation and unknown covar
00040   //
00041   //  The  covariance matrix is a zero matrix.
00042   rgrl_trans_rad_dis_homo2d( vnl_matrix<double> const& H,
00043                              double k1_from,
00044                              double k1_to,
00045                              vnl_vector<double> const& from_centre,
00046                              vnl_vector<double> const& to_centre );
00047 
00048   //: Construct a centered transform.
00049   //
00050   rgrl_trans_rad_dis_homo2d( vnl_matrix<double> const& H,
00051                              double k1_from,
00052                              double k1_to,
00053                              vnl_matrix<double> const& covar,
00054                              vnl_vector<double> const& from_centre,
00055                              vnl_vector<double> const& to_centre );
00056 
00057   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p  ) const;
00058 
00059   //: radial distortion term on From image
00060   double k1_from() const { return k1_from_; }
00061 
00062   //: radial distortion term on To image
00063   double k1_to() const { return k1_to_; }
00064 
00065   //: From center
00066   vnl_vector<double> from_centre() const { return from_centre_.as_ref(); }
00067 
00068   //: To center
00069   vnl_vector<double> to_centre() const { return to_centre_.as_ref(); }
00070 
00071   //: Inverse map using pseudo-inverse of H_.
00072   void inv_map( const vnl_vector<double>& to,
00073                 vnl_vector<double>& from ) const;
00074 
00075   //: is this an invertible transformation?
00076   bool is_invertible() const { return false; }
00077 
00078   //: Return an inverse transformation of the uncentered transform
00079   rgrl_transformation_sptr inverse_transform() const;
00080 
00081   //: Compute jacobian w.r.t. location
00082   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00083 
00084   //:  transform the transformation for images of different resolution
00085   rgrl_transformation_sptr scale_by( double scale ) const;
00086 
00087   //: The H matrix of the transform
00088   vnl_matrix_fixed<double, 3, 3> const& H() const { return H_; }
00089 
00090   // uncenter H matrix
00091   vnl_matrix_fixed<double, 3, 3>
00092   uncenter_H_matrix( ) const;
00093 
00094   //: log of determinant of the covariance
00095   virtual double
00096   log_det_covar() const
00097   { return log_det_covar_deficient( 10 ); }
00098 
00099   // Defines type-related functions
00100   rgrl_type_macro( rgrl_trans_rad_dis_homo2d, rgrl_transformation );
00101 
00102   // for output UNCENTERED transformation, with the origin as the center.
00103   void write(vcl_ostream& os ) const;
00104 
00105   // for input
00106   bool read(vcl_istream& is );
00107 
00108   //: make a clone copy
00109   rgrl_transformation_sptr clone() const;
00110 
00111  protected:
00112   void map_loc( vnl_vector<double> const& from,
00113                 vnl_vector<double>      & to ) const;
00114 
00115   void map_dir( vnl_vector<double> const& from_loc,
00116                 vnl_vector<double> const& from_dir,
00117                 vnl_vector<double>      & to_dir    ) const;
00118 
00119  private:
00120   vnl_matrix_fixed<double, 3, 3> H_;
00121   vnl_vector_fixed<double, 2> from_centre_;
00122   vnl_vector_fixed<double, 2> to_centre_;
00123 
00124   double k1_from_;
00125   double k1_to_;
00126 };
00127 
00128 #endif