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   //:  Clear record of results from previous runs
00047   void clear_results();
00048 
00049   //: Running from multiple initial estimates, produced by the initializer during registration
00050   //
00051   //  Loop through the set of initial estimates.
00052   void run( rgrl_initializer_sptr initializer );
00053 
00054   //: Running from a given initial estimate.
00055   //
00056   //  Based on if data_->is_multi_feature(), call run_single_feature(.)
00057   //  or run_multi_feature(.)
00058   //
00059   void run( rgrl_mask_box              from_image_region,
00060             rgrl_mask_box              to_image_region,
00061             rgrl_estimator_sptr        estimator,
00062             rgrl_transformation_sptr   initial_xform,
00063             rgrl_scale_sptr            prior_scale = 0,
00064             unsigned                   init_resolution = 0);
00065 
00066   //////////////// functions to access internal data  ////////////////////////
00067 
00068   //:  Return the final, best estimate
00069   rgrl_transformation_sptr final_transformation() const;
00070 
00071   //:  Return the scales of the best transformation estimate
00072   rgrl_set_of<rgrl_scale_sptr>  const& final_scales() const;
00073   rgrl_scale_sptr final_scale() const;
00074 
00075   //:  Return the status of the best transformation estimate.
00076   rgrl_converge_status_sptr final_status() const;
00077 
00078   //:  The multiple match sets used for the best transformation estimate.
00079   rgrl_set_of<rgrl_match_set_sptr> const& final_match_sets() const;
00080 
00081   //:  The single match set used for the best transformation estimate.
00082   rgrl_match_set_sptr final_match_set() const;
00083 
00084   //:  Return the number of initial transformations tested
00085   //
00086   //   The value might be greater than 1 if using initializer which
00087   //   provides a number of initial estimates.
00088   unsigned num_initial_xforms_tested() const;
00089 
00090   //:  Return true if has a best xform_estimate
00091   bool has_final_transformation() const;
00092 
00093   //: Set the max number of icp iteration per stage
00094   //
00095   //  The default is 25 at initialization
00096   void set_max_icp_iter( unsigned iter );
00097 
00098   //: Set the expected maximum geometric scale
00099   //
00100   //  If \a expected_max_geometric_scale_ is never set, the default
00101   //  has no effect on the registration.
00102   void set_expected_max_geometric_scale( double scale);
00103 
00104   //: Set the expected minimum geometric scale
00105   //
00106   //  If \a expected_min_geometric_scale_ is never set, the default
00107   //  has no effect on the registration.
00108   void set_expected_min_geometric_scale( double scale);
00109 
00110   //: Set the number of iterations during which the scale is to be estimated
00111   //
00112   //  If \a iterations_for_scale_est_ is never set, the default
00113   //  has no effect on the registration.
00114   void set_iterations_for_scale_est( int iter);
00115 
00116   //: penalize transformation that involves scaling of the registration area
00117   void penalize_scaling( bool );
00118 
00119   //: Return the current match sets
00120   rgrl_set_of<rgrl_match_set_sptr>  const& current_match_sets() const;
00121 
00122   //:  Return the current estimate
00123   rgrl_transformation_sptr current_transformation() const;
00124 
00125   //:  Return the current stage
00126   unsigned current_stage() const;
00127 
00128   //:  Return the current iterations_at_stage_
00129   unsigned iterations_at_current_stage() const;
00130 
00131  private:
00132   //: registration of single feature type at each stage/resolution
00133   void register_single_feature( rgrl_mask_box            from_image_region,
00134                                 rgrl_mask_box            to_image_region,
00135                                 rgrl_estimator_sptr      initial_xform_estimator,
00136                                 rgrl_transformation_sptr xform_estimate,
00137                                 rgrl_scale_sptr          prior_scale,
00138                                 unsigned                 init_resolution);
00139 
00140   //: registration of multiple feature types at each stage/resolution
00141   void register_multi_feature( rgrl_mask_box            from_image_region,
00142                                rgrl_mask_box            to_image_region,
00143                                rgrl_estimator_sptr      initial_xform_estimator,
00144                                rgrl_transformation_sptr xform_estimate,
00145                                rgrl_scale_sptr          prior_scale,
00146                                unsigned                 init_resolution);
00147 
00148 
00149   //: Scale/shrink the registration region and the \a xform_est according to the \a dim_increase_for_next_stage at \a current_resol
00150   void initialize_for_next_resolution(  rgrl_mask_box            & from_image_region,
00151                                         rgrl_mask_box            & to_image_region,
00152                                         rgrl_transformation_sptr & xform_estimate,
00153                                         unsigned                 & current_resol ) const;
00154 
00155  private:
00156   rgrl_data_manager_sptr data_;
00157   rgrl_convergence_tester_sptr conv_tester_;
00158 
00159   rgrl_converge_status_sptr          best_status_;
00160   rgrl_transformation_sptr           best_xform_estimate_;
00161   rgrl_set_of<rgrl_match_set_sptr>   best_matches_;
00162   rgrl_set_of<rgrl_scale_sptr>       best_scales_;
00163 
00164   unsigned num_xforms_tested_;
00165   unsigned max_icp_iter_;
00166   double   expected_max_geometric_scale_; //for early termination
00167   double   expected_min_geometric_scale_;
00168   int      iterations_for_scale_est_;
00169   bool     should_penalize_scaling_;
00170 
00171   // data members to keep track of current status
00172   unsigned                          current_stage_;
00173   unsigned                          iterations_at_stage_;
00174   rgrl_set_of<rgrl_match_set_sptr>  current_match_sets_;
00175   rgrl_transformation_sptr          current_xform_estimate_;
00176 };
00177 
00178 #endif // rgrl_feature_based_registration_h_