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