contrib/brl/bseg/sdet/sdet_edge_champher.h
Go to the documentation of this file.
00001 #ifndef sdet_edge_champher_h_
00002 #define sdet_edge_champher_h_
00003 
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \brief computes a distance transform for edge maps
00009 //
00010 // Uses the 3-4 chamfer distance transform on an array of edge pointers
00011 // to determine the distance from a point to the nearest edge.  The
00012 // edge pointer at a given location can be accessed.
00013 //
00014 // \verbatim
00015 // Modifications
00016 // Adapted from the original by Charlie Rothwell - 4/5/95
00017 // J.L. Mundy Nov.24, 2002
00018 // \endverbatim
00019 //
00020 //-----------------------------------------------------------------------------
00021 #include <vbl/vbl_array_2d.h>
00022 #include <vnl/vnl_numeric_traits.h>
00023 #include <vtol/vtol_edge_2d_sptr.h>
00024 class sdet_edge_champher
00025 {
00026   // PUBLIC INTERFACE----------------------------------------------------------
00027 
00028  public:
00029 
00030   // Constructors/Initializers/Destructors-------------------------------------
00031 
00032   sdet_edge_champher(vbl_array_2d<vtol_edge_2d_sptr>& edges);
00033   ~sdet_edge_champher();
00034 
00035   // Data Access---------------------------------------------------------------
00036 
00037   inline float distance(int x, int y) {
00038     int i = x;
00039     int j = y;
00040     // xsize_ = number of columns; ysize_ = number of rows
00041     if ( (i>=0) && (i<xsize_) && (j>=0) && (j<ysize_) )
00042         return (float) distance_[j][i];
00043     else
00044         return vnl_numeric_traits<float>::maxval;
00045     }
00046 
00047   inline vtol_edge_2d_sptr image_edge(int x, int y) {
00048     int i = x;
00049     int j = y;
00050     // xsize_ = number of columns; ysize_ = number of rows
00051     if ( (i>=0) && (i<xsize_) && (j>=0) && (j<ysize_) )
00052         return edges_[j][i];
00053     else
00054         return 0;
00055     }
00056 
00057   // Data Control--------------------------------------------------------------
00058 
00059   // Utility Methods-----------------------------------------------------------
00060   void distance_with_edge_masked(int x, int y, vtol_edge_2d_sptr& e);
00061   // INTERNALS-----------------------------------------------------------------
00062   void initialize_arrays(vbl_array_2d<vtol_edge_2d_sptr>& edges);
00063   void chamfer_34();
00064   int minimum_5(int,int,int,int,int);
00065   void forward_chamfer();
00066   void backward_chamfer();
00067   void compute_real_distances();
00068  protected:
00069 
00070   // Data Members--------------------------------------------------------------
00071 
00072  private:
00073 
00074   // Various pieces of image info
00075   int xsize_,ysize_;
00076 
00077   // The distance image
00078   vbl_array_2d<unsigned char> distance_;
00079   // Pointers to the nearest Edge for each pixel;
00080   vbl_array_2d<vtol_edge_2d_sptr> edges_;
00081 
00082   // The index of the digital curve element at a given pixel
00083   int **index_;
00084 };
00085 
00086 #endif