contrib/rpl/rgrl/rgrl_trans_homo2d_proj_rad.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_homo2d_proj_rad_h_
00002 #define rgrl_trans_homo2d_proj_rad_h_
00003 //:
00004 // \file
00005 // \author Gehua Yang
00006 // \date   March 2007
00007 // \brief  Represents a 2D homography plus radial distortion transformation.
00008 
00009 #include "rgrl_transformation.h"
00010 #include <rgrl/rgrl_est_proj_rad_func.h>
00011 #include <vnl/vnl_matrix_fixed.h>
00012 #include <vcl_iosfwd.h>
00013 
00014 //: Represents a 2D homography plus radial distortion transformation.
00015 //  A transformation for x'_u=Hx, and x'_d = x'_u + k*radial_dist( x'_u )
00016 class rgrl_trans_homo2d_proj_rad
00017   : public rgrl_transformation,
00018     public rgrl_est_proj_rad_func<2, 2>
00019 {
00020   vnl_matrix_fixed<double,3,3> H_;
00021   vcl_vector<double>           rad_k_;
00022  public:
00023   //: Initialize to the identity matrix
00024   rgrl_trans_homo2d_proj_rad();
00025 
00026   //: Constructor based on an initial transformation and covar estimate
00027   //  The radial parameters are assumed to be unnormalized.
00028   rgrl_trans_homo2d_proj_rad( vnl_matrix_fixed<double, 3, 3> const& H,
00029                               vcl_vector<double>             const & k,
00030                               vnl_vector_fixed< double, 2 >  const & image_centre );
00031 
00032   //: Constructor based on an initial transformation and unknown covar
00033   //  The covariance matrix is a zero matrix.
00034   rgrl_trans_homo2d_proj_rad( vnl_matrix<double> const& H );
00035 
00036   //: Construct a centered transform.
00037   //  The radial parameters are assumed to be unnormalized.
00038   rgrl_trans_homo2d_proj_rad( vnl_matrix_fixed<double, 3, 3> const& H,
00039                               vcl_vector<double>             const & k,
00040                               vnl_vector_fixed< double, 2 >  const & image_centre,
00041                               vnl_matrix<double> const& covar,
00042                               vnl_vector<double> const& from_centre,
00043                               vnl_vector<double> const& to_centre );
00044 
00045   //: Constructor based on an initial transformation and covar estimate
00046   //  The radial parameters are assumed to be normalized.
00047   rgrl_trans_homo2d_proj_rad( vcl_vector<double>             const & norm_k,
00048                               vnl_matrix_fixed<double, 3, 3> const& H,
00049                               vnl_vector_fixed< double, 2 >  const & image_centre );
00050 
00051   //: Construct a centered transform.
00052   //  The radial parameters are assumed to be normalized.
00053   rgrl_trans_homo2d_proj_rad( vcl_vector<double>             const & norm_k,
00054                               vnl_matrix_fixed<double, 3, 3> const& H,
00055                               vnl_vector_fixed< double, 2 >  const & image_centre,
00056                               vnl_matrix<double> const& covar,
00057                               vnl_vector<double> const& from_centre,
00058                               vnl_vector<double> const& to_centre );
00059 
00060   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p  ) const;
00061 
00062   //: Compute jacobian w.r.t. location
00063   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00064 
00065   //:  transform the transformation for images of different resolution
00066   rgrl_transformation_sptr scale_by( double scale ) const;
00067 
00068   //: log of determinant of the covariance
00069   virtual double
00070   log_det_covar() const
00071   { return log_det_covar_deficient( 8+camera_dof_ ); }
00072 
00073   //: Defines type-related functions
00074   rgrl_type_macro( rgrl_trans_homo2d_proj_rad, rgrl_transformation );
00075 
00076   //: for output UNCENTERED transformation, with the origin as the center.
00077   void write(vcl_ostream& os ) const;
00078 
00079   //: for input
00080   bool read(vcl_istream& is );
00081 
00082   //: make a clone copy
00083   rgrl_transformation_sptr clone() const;
00084 
00085   //: The scaling and rotation component of the transform
00086   vnl_matrix_fixed<double, 3, 3> H() const;
00087 
00088   //: return unnormalized radial parameters
00089   vcl_vector<double>
00090   radial_params() const;
00091 
00092   //: return the normalized radial parameters
00093   vcl_vector<double> const&
00094   normalized_radial_params() const
00095   { return rad_k_; }
00096 
00097  protected:
00098   void map_loc( vnl_vector<double> const& from,
00099                 vnl_vector<double>      & to  ) const;
00100 
00101   void map_dir( vnl_vector<double> const& from_loc,
00102                 vnl_vector<double> const& from_dir,
00103                 vnl_vector<double>      & to_dir  ) const;
00104 
00105   void set_up_rad_k(vcl_vector<double> const & rad_k);
00106 };
00107 
00108 #endif // rgrl_trans_homo2d_proj_rad_h_