contrib/rpl/rgrl/rgrl_matcher_pseudo.h
Go to the documentation of this file.
00001 #ifndef rgrl_matcher_pseudo_h_
00002 #define rgrl_matcher_pseudo_h_
00003 //:
00004 // \file
00005 // \author Chuck Stewart
00006 // \date   Sept 2003
00007 
00008 #include <rgrl/rgrl_matcher.h>
00009 #include <rgrl/rgrl_feature_set.h>
00010 #include <rgrl/rgrl_view.h>
00011 #include <rgrl/rgrl_transformation.h>
00012 #include <rgrl/rgrl_scale.h>
00013 #include <rgrl/rgrl_feature_sptr.h>
00014 #include "rgrl_evaluator.h"
00015 #include <rgrl/rgrl_mask_sptr.h>
00016 #include <rgrl/rgrl_mask.h>
00017 #include <vil/vil_image_view.h>
00018 #include <vnl/vnl_vector.h>
00019 #include <vnl/vnl_double_2.h>
00020 #include "rgrl_evaluator_sptr.h"
00021 
00022 //: For each "from" pseudo / weak feature, use intensity based matching to construct the "to" features.
00023 //
00024 // This will map the "from" feature and its surrounding region using
00025 // the current transformation, and search for the best
00026 // intensity-region match to construct the "to" feature.
00027 //
00028 // EvaluatorType, which perhaps should be a base class, takes two
00029 // voxel lists and calculates a similarity measure between them.  This
00030 // says how well two subregions match. (F in notes)
00031 
00032 template < class PixelType >
00033 class rgrl_matcher_pseudo
00034   : public rgrl_matcher
00035 {
00036  public:
00037 
00038 //   typedef vnl_vector< PixelType > rgrl_pixel_type;
00039 
00040   class rgrl_mapped_pixel_type {
00041    public:
00042     vnl_double_2  location;
00043     double              intensity;
00044     double              weight;
00045   };
00046 
00047   typedef vcl_vector< rgrl_mapped_pixel_type > rgrl_mapped_pixel_vector_type;
00048 
00049   //: Initialize the matcher using 2d images.
00050   //
00051   rgrl_matcher_pseudo( vil_image_view<PixelType> from_image,
00052                        vil_image_view<PixelType> to_image,
00053                        rgrl_evaluator_sptr evaluator,
00054                        rgrl_mask_sptr from_mask = 0,
00055                        rgrl_mask_sptr to_mask = 0 );
00056 
00057   //: Match the features in the "from" image to the intensity in the "to" image.
00058   //
00059   rgrl_match_set_sptr
00060   compute_matches( rgrl_feature_set const&     from_features,
00061                    rgrl_feature_set const&     to_features,
00062                    rgrl_view const&            current_view,
00063                    rgrl_transformation const&  current_xform,
00064                    rgrl_scale const&           current_scale,
00065                    rgrl_match_set_sptr const& old_matches = 0 );
00066 
00067   // Defines type-related functions
00068   rgrl_type_macro( rgrl_matcher_pseudo, rgrl_matcher );
00069 
00070  private:
00071   //:  Map the intensities of the image region.
00072   void
00073   map_region_intensities( rgrl_transformation      const& trans,
00074                           rgrl_feature_sptr               feature_sptr,
00075                           rgrl_mapped_pixel_vector_type & mapped_pixels ) const;
00076 
00077   //:  The actual work of mapping the region intensities.
00078   void
00079   map_region_intensities( vcl_vector< vnl_vector<int> > const& pixel_locations,
00080                           rgrl_transformation           const& trans,
00081                           rgrl_feature_sptr                    feature_sptr,
00082                           rgrl_mapped_pixel_vector_type      & mapped_pixels) const;
00083 
00084   void
00085   match_mapped_region( rgrl_feature_sptr                    mapped_feature,
00086                        rgrl_mapped_pixel_vector_type const& mapped_pixels,
00087                        rgrl_scale                    const& current_scale,
00088                        vcl_vector< rgrl_feature_sptr >    & matched_to_features,
00089                        vcl_vector< double >               & match_weights ) const;
00090 
00091   double compute_response( vnl_double_2                  const& mapped_location,
00092                            rgrl_mapped_pixel_vector_type const& mapped_pixels,
00093                            vnl_double_2                  const& shift ) const;
00094 
00095  private:
00096 #if 0
00097   typedef itkImage< PixelType, Dimension > ImageType;
00098 #endif
00099 
00100   //  These are currently only for 2d images.  ITK templates across
00101   //  dimension.  VXL / rgrl does not.  Need to work with ITK images
00102   vil_image_view<PixelType> from_image_;
00103   vil_image_view<PixelType> to_image_;
00104 
00105   // When we try to search for the best match, we have to make sure
00106   // only the points inside the valid region are considered. The mask_
00107   // here seems to be duplicate with the mask_ in
00108   // rgrl_feature_set_location_masked.  But it seems to me that it
00109   // can't be avoid to put another mask_ here with the current design.
00110   // Also, this is also temporary for retina images. - Bess.
00111   rgrl_mask_sptr from_mask_;
00112   rgrl_mask_sptr to_mask_;
00113   rgrl_evaluator_sptr evaluator_;
00114 };
00115 
00116 #endif // rgrl_matcher_pseudo_h_