00001 #ifndef mbl_correspond_points_h_ 00002 #define mbl_correspond_points_h_ 00003 //: 00004 // \file 00005 // \brief Shapiro & Brady's point correspondence algorithm 00006 // \author Tim Cootes 00007 00008 #include <vcl_vector.h> 00009 #include <vnl/vnl_vector.h> 00010 #include <vnl/vnl_matrix.h> 00011 #include <vgl/vgl_point_2d.h> 00012 00013 //: Shapiro & Brady's point correspondence algorithm. 00014 // Includes improvements by Carcassoni and Hancock (a robust kernel 00015 // in the distance metric). 00016 // 00017 // Note that current version can't cope with different numbers of points. 00018 // Need to re-order eigenvectors by absolute magnitude of eigenvalues. 00019 // I'll do this soon - Tim. 00020 class mbl_correspond_points 00021 { 00022 private: 00023 //: Eigenvalues of proximity matrix 1 00024 vnl_vector<double> evals1_; 00025 //: Eigenvalues of proximity matrix 2 00026 vnl_vector<double> evals2_; 00027 00028 //: Return index of row in H2 most similar to row i of H1 00029 unsigned closest_row(const vnl_matrix<double>& H1, 00030 const vnl_matrix<double>& H2, 00031 unsigned i); 00032 00033 //: Ensure each column vector points in the same way 00034 // Unit eigenvectors can point in one of two directions. 00035 // Ensure p.1>=0 to obtain consistancy. 00036 void fix_eigenvectors(vnl_matrix<double>& P); 00037 00038 public: 00039 00040 //: Dflt ctor 00041 mbl_correspond_points(); 00042 00043 //: Find best correspondence between points1 and points2 00044 // On exit, matches[i] gives index of points2 which 00045 // corresponds to points1[i]. 00046 // Note that there may be a many to one correspondence produced. 00047 // \param sigma Scaling factor defining kernel width 00048 void correspond(const vcl_vector<vgl_point_2d<double> >& points1, 00049 const vcl_vector<vgl_point_2d<double> >& points2, 00050 vcl_vector<unsigned>& matches, double sigma); 00051 00052 //: Construct proximity matrix using cosh kernel 00053 // On exit, D(i,j) = tanh(pi*d_ij/sigma) * 2/(pi*d_ij) 00054 // where d_ij is the distance between points i and j 00055 void proximity_by_tanh(const vcl_vector<vgl_point_2d<double> >& points, 00056 vnl_matrix<double>& H, double sigma); 00057 00058 //: Eigenvalues of proximity matrix 1 in last call to correspond 00059 const vnl_vector<double>& evals1() const { return evals1_; } 00060 00061 //: Eigenvalues of proximity matrix 2 in last call to correspond 00062 const vnl_vector<double>& evals2() const { return evals2_; } 00063 }; 00064 00065 #endif //mbl_correspond_points_h_