contrib/brl/bseg/brip/brip_gain_offset_solver.h
Go to the documentation of this file.
00001 // This is brl/bseg/brip/brip_gain_offset_solver.h
00002 #ifndef brip_gain_offset_solver_h_
00003 #define brip_gain_offset_solver_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \date February 26, 2012
00009 // \brief Finds a gain and offset intensity map that minimizes squared difference between images.
00010 //
00011 // In order to accurately compare images that have corresponding pixel
00012 // intensities it is necessary to adjust the gain and offset of the test
00013 // image to match the model image as closely as possible. It is assumed
00014 // that both the model and test images are the same size and corresponding
00015 // pixels represent the same scene surface element, i.e. should have the
00016 // same intensity
00017 //
00018 // \verbatim
00019 //  Modifications
00020 //   none yet
00021 // \endverbatim
00022 //
00023 //-----------------------------------------------------------------------------
00024 #include <vil/vil_image_view.h>
00025 
00026 class brip_gain_offset_solver
00027 {
00028  public:
00029 
00030   brip_gain_offset_solver() : ni_(0), nj_(0), gain_(1.0f), offset_(0.0f),
00031     t_mask_(false), m_mask_(false), n_valid_pix_(0) {}
00032 
00033   //: constructor with images, which are used in entirety
00034   brip_gain_offset_solver(vil_image_view<float> const& model_image,
00035                           vil_image_view<float> const& test_image);
00036 
00037   //: constructor with images and masks. pixels with mask(i,j)=true are valid
00038   brip_gain_offset_solver(vil_image_view<float> const& model_image,
00039                           vil_image_view<float> const& test_image,
00040                           vil_image_view<unsigned char> const& model_mask,
00041                           vil_image_view<unsigned char> const& test_mask);
00042 
00043   ~brip_gain_offset_solver() {}
00044 
00045   //: set images after default construction
00046   void set_model_image(vil_image_view<float> const& image) {model_image_ = image;}
00047   void set_test_image (vil_image_view<float> const& image) {test_image_ = image;}
00048   //: set masks to define valid pixels in each image. Otherwise entire image is used
00049   void set_model_mask(vil_image_view<unsigned char> const& mask) {model_mask_ = mask;}
00050   void set_test_mask (vil_image_view<unsigned char> const& mask) {test_mask_ = mask;}
00051 
00052   //: accessors
00053   unsigned ni() const {return ni_;}
00054   unsigned nj() const {return nj_;}
00055   float gain()  const {return gain_;}
00056   float offset()const {return offset_;}
00057   //: operations
00058   bool solve();
00059   //:transform the test image by the solved gain and offset
00060   vil_image_view<float> mapped_test_image();
00061  protected:
00062   //: internal methods
00063   void compute_valid_pix();
00064   //: members
00065   unsigned ni_, nj_;
00066   vil_image_view<float> model_image_;
00067   vil_image_view<float> test_image_;
00068   float gain_;
00069   float offset_;
00070   vil_image_view<unsigned char> model_mask_;
00071   vil_image_view<unsigned char> test_mask_;
00072   bool t_mask_;
00073   bool m_mask_;
00074   unsigned n_valid_pix_;
00075 };
00076 
00077 #endif // brip_gain_offset_solver_h_