contrib/brl/bseg/sdet/sdet_gauss_fit.h
Go to the documentation of this file.
00001 // This is brl/bseg/sdet/sdet_gauss_fit.h
00002 #ifndef sdet_gauss_fit_h_
00003 #define sdet_gauss_fit_h_
00004 //:
00005 // \file
00006 // \brief Fit 2d gaussian to a small peak in image intensity
00007 // \author J. Green
00008 // patterned after Joe Mundy's vpgl_rational_adjust
00009 // \date August 12, 2007
00010 //
00011 
00012 #include <vcl_vector.h>
00013 #include <vnl/vnl_vector.h>
00014 #include <vnl/vnl_least_squares_function.h>
00015 #include <vgl/vgl_point_3d.h>
00016 #include <vsol/vsol_point_2d_sptr.h>
00017 
00018 //: Class to fit a 2-d Gaussian to small peaks in a polygon drawn on image.
00019 //  This class started out to fit one peak in a polygon area, but has been
00020 //  expanded to fit up to 4 peaks.  The approximate locations of the peaks
00021 //  (1-4) are picked using the pick_point_set() method that was added to
00022 //  the bgui_picker_tableau class.
00023 
00024 class sdet_adjust_lsqr : public vnl_least_squares_function
00025 {
00026  public:
00027   //: Constructor
00028   sdet_adjust_lsqr( vcl_vector<vgl_point_3d<double> > const& img_pts,
00029                     unsigned int num_unknowns, unsigned int num_residuals,
00030                     int n_peaks);
00031 
00032   // Destructor
00033   virtual ~sdet_adjust_lsqr() {}
00034 
00035   //: The main function.
00036   //  Given the parameter vector x, compute the vector of residuals fx.
00037   virtual void f(vnl_vector<double> const& x, vnl_vector<double>& fx);
00038 
00039 #if 0
00040   //: Called after each LM iteration to print debugging etc.
00041   virtual void trace(int iteration, vnl_vector<double> const& x,
00042                      vnl_vector<double> const& fx);
00043 #endif
00044 
00045  protected:
00046  // 3 value vector;  1&2 are x&y indices of pixel, 3 is intensity of pixel;
00047   vcl_vector<vgl_point_3d<double> > img_pts_;
00048   unsigned num_pixels_;
00049   int n_peaks_;
00050 };
00051 
00052 class sdet_gauss_fit
00053 {
00054  public:
00055   ~sdet_gauss_fit(){}
00056 
00057   static vnl_vector<double> adjust(vcl_vector<vgl_point_3d<double> > img_pts,
00058                                    vcl_vector<vsol_point_2d_sptr> ps_list,
00059                                    int n_peaks,
00060                                    vcl_ofstream& outfile,
00061                                    double xmin, double ymin);
00062 
00063   static vnl_vector<double> calculate_ellipse(vnl_vector<double> result,
00064                                               float x,
00065                                               float y,
00066                                               int i,
00067                                               int n_peaks,
00068                                               vcl_ofstream& outfile);
00069 
00070  protected:
00071   sdet_gauss_fit();
00072 };
00073 
00074 #endif // sdet_gauss_fit_h_