contrib/rpl/rgrl/rgrl_feature_based_registration.h
Go to the documentation of this file.
00001 #ifndef rgrl_feature_based_registration_h_
00002 #define rgrl_feature_based_registration_h_
00003 //:
00004 // \file
00005 // \brief The engine for feature-based registration.
00006 // \author Charlene Tsai
00007 // \date   Feb 2004
00008 
00009 #include "rgrl_object.h"
00010 #include "rgrl_data_manager_sptr.h"
00011 #include "rgrl_convergence_tester_sptr.h"
00012 #include "rgrl_estimator_sptr.h"
00013 #include "rgrl_transformation_sptr.h"
00014 #include "rgrl_set_of.h"
00015 #include "rgrl_scale_sptr.h"
00016 #include "rgrl_initializer_sptr.h"
00017 #include "rgrl_converge_status_sptr.h"
00018 #include "rgrl_match_set_sptr.h"
00019 #include "rgrl_weighter_sptr.h"
00020 #include "rgrl_mask.h"
00021 
00022 //: Feature-based registration
00023 //
00024 //  The registration engine takes a data storage of single- or
00025 //  multiple-stage/resolution. Each stage may contain multiple feature
00026 //  types. Different transformation estimators may be assigned to
00027 //  different stages. The limitations of feature-based registration
00028 //  are fixed registration region and estimator at each stage.
00029 //
00030 class rgrl_feature_based_registration: public rgrl_object
00031 {
00032  public:
00033   //: Initialize with the data storage and the convergence tester
00034   rgrl_feature_based_registration( rgrl_data_manager_sptr data,
00035                                    rgrl_convergence_tester_sptr conv_tester );
00036   //: Initialize with the data storage.
00037   //
00038   //  The default convergence tester is set to median error
00039   rgrl_feature_based_registration( rgrl_data_manager_sptr data );
00040 
00041   ~rgrl_feature_based_registration();
00042 
00043   // Defines type-related functions
00044   rgrl_type_macro( rgrl_feature_based_registration, rgrl_object );
00045 
00046   
00047   //:  Clear record of results from previous runs
00048   void clear_results();
00049 
00050   //: Running from multiple initial estimates, produced by the initializer during registration
00051   //
00052   //  Loop through the set of initial estimates.
00053   void run( rgrl_initializer_sptr initializer );
00054 
00055   //: Running from a given initial estimate.
00056   //
00057   //  Based on if data_->is_multi_feature(), call run_single_feature(.)
00058   //  or run_multi_feature(.)
00059   //
00060   void run( rgrl_mask_box              from_image_region,
00061             rgrl_mask_box              to_image_region,
00062             rgrl_estimator_sptr        estimator,
00063             rgrl_transformation_sptr   initial_xform,
00064             rgrl_scale_sptr            prior_scale = 0,
00065             unsigned                   init_resolution = 0);
00066 
00067   //////////////// functions to access internal data  ////////////////////////
00068 
00069   //:  Return the final, best estimate
00070   rgrl_transformation_sptr final_transformation() const;
00071 
00072   //:  Return the scales of the best transformation estimate
00073   rgrl_set_of<rgrl_scale_sptr>  const& final_scales() const;
00074   rgrl_scale_sptr final_scale() const;
00075 
00076   //:  Return the status of the best transformation estimate.
00077   rgrl_converge_status_sptr final_status() const;
00078 
00079   //:  The multiple match sets used for the best transformation estimate.
00080   rgrl_set_of<rgrl_match_set_sptr> const& final_match_sets() const;
00081 
00082   //:  The single match set used for the best transformation estimate.
00083   rgrl_match_set_sptr final_match_set() const;
00084 
00085   //:  Return the number of initial transformations tested
00086   //
00087   //   The value might be greater than 1 if using initializer which
00088   //   provides a number of initial estimates.
00089   unsigned num_initial_xforms_tested() const;
00090 
00091   //:  Return true if has a best xform_estimate
00092   bool has_final_transformation() const;
00093 
00094   //: Set the max number of icp iteration per stage
00095   //
00096   //  The default is 25 at initialization
00097   void set_max_icp_iter( unsigned iter );
00098 
00099   //: Set the expected maximum geometric scale
00100   //
00101   //  If \a expected_max_geometric_scale_ is never set, the default
00102   //  has no effect on the registration.
00103   void set_expected_max_geometric_scale( double scale);
00104 
00105   //: Set the expected minimum geometric scale
00106   //
00107   //  If \a expected_min_geometric_scale_ is never set, the default
00108   //  has no effect on the registration.
00109   void set_expected_min_geometric_scale( double scale);
00110 
00111   //: Set the number of iterations during which the scale is to be estimated
00112   //
00113   //  If \a iterations_for_scale_est_ is never set, the default
00114   //  has no effect on the registration.
00115   void set_iterations_for_scale_est( int iter);
00116 
00117   //: penalize transformation that involves scaling of the registraion area
00118   void penalize_scaling( bool );
00119 
00120   //: Return the current match sets
00121   rgrl_set_of<rgrl_match_set_sptr>  const& current_match_sets() const;
00122 
00123   //:  Return the current estimate
00124   rgrl_transformation_sptr current_transformation() const;
00125 
00126   //:  Return the current stage
00127   unsigned current_stage() const;
00128 
00129   //:  Return the current iterations_at_stage_
00130   unsigned iterations_at_current_stage() const;
00131 
00132  private:
00133   //: registration of single feature type at each stage/resolution
00134   void register_single_feature( rgrl_mask_box            from_image_region,
00135                                 rgrl_mask_box            to_image_region,
00136                                 rgrl_estimator_sptr      initial_xform_estimator,
00137                                 rgrl_transformation_sptr xform_estimate,
00138                                 rgrl_scale_sptr          prior_scale,
00139                                 unsigned                 init_resolution);
00140 
00141   //: registration of multiple feature types at each stage/resolution
00142   void register_multi_feature( rgrl_mask_box            from_image_region,
00143                                rgrl_mask_box            to_image_region,
00144                                rgrl_estimator_sptr      initial_xform_estimator,
00145                                rgrl_transformation_sptr xform_estimate,
00146                                rgrl_scale_sptr          prior_scale,
00147                                unsigned                 init_resolution);
00148 
00149 
00150   //: Scale/shrink the registration region and the \a xform_est according to the \a dim_increase_for_next_stage at \a current_resol
00151   void initialize_for_next_resolution(  rgrl_mask_box            & from_image_region,
00152                                         rgrl_mask_box            & to_image_region,
00153                                         rgrl_transformation_sptr & xform_estimate,
00154                                         unsigned                 & current_resol ) const;
00155 
00156  private:
00157   rgrl_data_manager_sptr data_;
00158   rgrl_convergence_tester_sptr conv_tester_;
00159 
00160   rgrl_converge_status_sptr          best_status_;
00161   rgrl_transformation_sptr           best_xform_estimate_;
00162   rgrl_set_of<rgrl_match_set_sptr>   best_matches_;
00163   rgrl_set_of<rgrl_scale_sptr>       best_scales_;
00164 
00165   unsigned num_xforms_tested_;
00166   unsigned max_icp_iter_;
00167   double   expected_max_geometric_scale_; //for early termination
00168   double   expected_min_geometric_scale_;
00169   int      iterations_for_scale_est_;
00170   bool     should_penalize_scaling_;
00171 
00172   // data members to keep track of current status
00173   unsigned                          current_stage_;
00174   unsigned                          iterations_at_stage_;
00175   rgrl_set_of<rgrl_match_set_sptr>  current_match_sets_;
00176   rgrl_transformation_sptr          current_xform_estimate_;
00177 };
00178 
00179 #endif // rgrl_feature_based_registration_h_