contrib/brl/bseg/sdet/sdet_denoise_mrf.h
Go to the documentation of this file.
00001 // This is brl/bseg/sdet/sdet_denoise_mrf.h
00002 #ifndef sdet_denoise_mrf_h_
00003 #define sdet_denoise_mrf_h_
00004 //---------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief a processor applying a binary mrf denoise algorithm
00008 //
00009 //
00010 //  This algorithm selectively smooths the image based on
00011 //  a variance value at each pixel. The smoothing is carried out
00012 //  by a MRF with binary cliques, where the clique energy weights
00013 //  are controlled in part by the variance image.
00014 //
00015 //
00016 // \author
00017 //  J.L. Mundy - March 22, 2011
00018 //
00019 //
00020 // The mrf energy minimization is carried out with a closed form algorithm
00021 // i.e. non-iterative as compared with belief propagation,
00022 // which requires iterations of message passing. The algorithm is based in
00023 // part on the paper:
00024 // "Continuous MRF-based image denoising with a closed form solution,"
00025 // Ming Liu, Shifeng Chen, and Jianzhuang Liu
00026 //  Proc. IEEE 17th International Conference on Image Processing, 2010
00027 //
00028 //
00029 // \verbatim
00030 //  Modifications
00031 //   <none>
00032 // \endverbatim
00033 //
00034 //-------------------------------------------------------------------------
00035 #include <vcl_vector.h>
00036 #include <vnl/vnl_vector.h>
00037 #include <sdet/sdet_denoise_mrf_params.h>
00038 #include <vil/vil_image_resource.h>
00039 #include <vil/vil_image_view.h>
00040 #include <vnl/vnl_sparse_matrix.h>
00041 class sdet_denoise_mrf : public sdet_denoise_mrf_params
00042 {
00043  public:
00044   // === Constructors/destructor ===
00045 
00046   sdet_denoise_mrf(sdet_denoise_mrf_params& imp);
00047   ~sdet_denoise_mrf();
00048 
00049   // === Process methods ===
00050 
00051   void set_image(vil_image_resource_sptr const& resource) { in_resc_ = resource; }
00052   void set_variance(vil_image_resource_sptr const& var_resc)
00053     { var_resc_ = var_resc; }
00054 
00055   //: construct the mrf graph incidence matrix (no output image)
00056   // W and D are valid after construction
00057   void compute_incidence_matrix();
00058 
00059   //: the full denoising process
00060   bool denoise();
00061 
00062   // === Accessors ===
00063 
00064   vil_image_resource_sptr output() { return out_resc_; }
00065   bool output_valid() const { return output_valid_; }
00066   vnl_sparse_matrix<double>& incidence_matrix()  { return W_mat_; }
00067   vnl_sparse_matrix<double>& diag_matrix()  { return D_mat_; }
00068   vil_image_resource_sptr Dimgr();
00069   vnl_sparse_matrix<double>& diag_inv_sqrt()  { return D_inv_sqrt_; }
00070   vnl_sparse_matrix<double>& L() { return L_mat_; }
00071   vnl_vector<double>& F()  { return F_; }
00072 
00073  protected:
00074   // === protected methods ===
00075 
00076   //: compute the clique energy weight between two image locations
00077   double weight(unsigned i0, unsigned j0, unsigned i1, unsigned j1,
00078                 vil_image_view<float> const& depth,
00079                 vil_image_view<float> const& varv);
00080   //:the "L" matrix
00081   void compute_laplacian_matrix();
00082   //:the solution vector
00083   void compute_F();
00084 
00085   // === members ===
00086 
00087   bool output_valid_;      //process state flag
00088   double sigma_sq_inv_;
00089   vil_image_resource_sptr in_resc_;
00090   vil_image_resource_sptr var_resc_;
00091   vil_image_resource_sptr out_resc_;
00092   vnl_sparse_matrix<double> W_mat_;
00093   vnl_sparse_matrix<double> D_mat_;
00094   vnl_sparse_matrix<double> D_inv_sqrt_;
00095   vnl_sparse_matrix<double> L_mat_;
00096   vnl_sparse_matrix<double> inv_mat_;
00097   vnl_vector<double> F_;
00098 };
00099 
00100 #endif // sdet_denoise_mrf_h_