contrib/gel/vsrl/vsrl_image_correlation.h

Go to the documentation of this file.
00001 // This is gel/vsrl/vsrl_image_correlation.h
00002 #ifndef vsrl_image_correlation_h
00003 #define vsrl_image_correlation_h
00004 //:
00005 // \file
00006 
00007 #include <vxl_config.h>
00008 #include <vil1/vil1_memory_image_of.h>
00009 #include <vnl/vnl_matrix.h>
00010 
00011 typedef vil1_memory_image_of<vxl_byte> vil1_byte_buffer;
00012 
00013 class vil1_image;
00014 
00015 //:
00016 // this class will determine the correlation between two images for
00017 // a pair of regions
00018 
00019 class vsrl_image_correlation
00020 {
00021  public:
00022   // constructor
00023   vsrl_image_correlation(const vil1_image &im1, const vil1_image &im2);
00024 
00025   // destructor
00026   ~vsrl_image_correlation();
00027 
00028   //: set the correlation window width
00029   void set_window_width(int width);
00030 
00031   //: set the correlation window height
00032   void set_window_height(int height);
00033 
00034   //: the number of correlations used
00035   void set_correlation_range(int range);
00036   //: the number of correlations used
00037   int get_correlation_range();
00038 
00039   //: perform a set of initial calculations
00040   void initial_calculations();
00041 
00042   //: get the correlation using the initial calculations
00043   double get_correlation(int x1, int y1, int delta_x);
00044 
00045   //: we want to know how the correlation function behaves around the point x1 y1.
00046   void get_correlation_stats(int x, int y, double &mean, double &std);
00047 
00048   //: interpolate to get subpixel accuracy for delta_x
00049   double get_sub_pixel_delta(int x1, int y1, int delta_x);
00050 
00051   //: get the correlation directly
00052   double get_correlation(int x1, int y1, int x2, int y2);
00053 
00054   // get some stats regarding the buffers
00055 
00056   int get_image1_width();
00057   int get_image1_height();
00058 
00059   int get_image2_width();
00060   int get_image2_height();
00061 
00062   double get_image_value1(int x, int y);
00063   double get_image_value2(int x, int y);
00064 
00065   double get_mean_1(int x, int y);
00066   double get_mean_2(int x, int y);
00067   double get_std_1(int x, int y);
00068   double get_std_2(int x, int y);
00069 
00070  private:
00071 
00072   int window_width_;
00073   int window_height_;
00074   int correlation_range_;
00075 
00076   //: the results of initial correlations
00077   vnl_matrix<double> **image_correlations_;
00078 
00079   // the local stats
00080 
00081   vnl_matrix<double> *std_x_;
00082   vnl_matrix<double> *std_y_;
00083   vnl_matrix<double> *mean_x_;
00084   vnl_matrix<double> *mean_y_;
00085 
00086   //: get a matrix of means and stds for a given image
00087   void  compute_local_stats(vnl_matrix<double> &im, vnl_matrix<double> &mean, vnl_matrix<double> &std);
00088 
00089   //: compute the correlation for a given x offset
00090   void compute_correlation(int x_offset, vnl_matrix<double> &X, vnl_matrix<double> &Y, vnl_matrix<double> &mean_x,
00091                            vnl_matrix<double> &mean_y, vnl_matrix<double> &std_x, vnl_matrix<double> &std_y,
00092                            vnl_matrix<double> &corr_matrix);
00093 
00094   void shift_multiply_matrix(int offset, vnl_matrix<double> &X, vnl_matrix<double> &Y,
00095                              vnl_matrix<double> &XY);
00096 
00097   //: memory images of the data
00098 
00099   vil1_byte_buffer buffer1_;
00100   vil1_byte_buffer buffer2_;
00101 
00102   //: compute the local stats using the slow method.
00103   void compute_local_stats(vil1_byte_buffer &buf, int x, int y, double &mean, double &std);
00104 
00105   //: make sure that x and y are in the bounds of buf
00106   bool check_range(vil1_byte_buffer &buf, int x, int y);
00107 };
00108 
00109 #endif // vsrl_image_correlation_h

Generated on Mon Mar 8 05:24:39 2010 for contrib/gel/vsrl by  doxygen 1.5.1