PTdecode/CImg-1.3.0/plugins/noise_analysis.h

changeset 5
1204ebf9340d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/PTdecode/CImg-1.3.0/plugins/noise_analysis.h	Mon Aug 03 14:09:20 2009 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/*
     1.5 + #
     1.6 + #  File        : noise_analysis.h
     1.7 + #                ( C++ header file - CImg plug-in )
     1.8 + #
     1.9 + #  Description : CImg plug-in that estimates noise standard deviation.
    1.10 + #                This file is a part of the CImg Library project.
    1.11 + #                ( http://cimg.sourceforge.net )
    1.12 + #
    1.13 + #  Copyright   : Jerome Boulanger
    1.14 + #                ( http://www.irisa.fr/vista/Equipe/People/Jerome.Boulanger.html )
    1.15 + #
    1.16 + #  License     : CeCILL v2.0
    1.17 + #                ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
    1.18 + #
    1.19 + #  This software is governed by the CeCILL  license under French law and
    1.20 + #  abiding by the rules of distribution of free software.  You can  use,
    1.21 + #  modify and/ or redistribute the software under the terms of the CeCILL
    1.22 + #  license as circulated by CEA, CNRS and INRIA at the following URL
    1.23 + #  "http://www.cecill.info".
    1.24 + #
    1.25 + #  As a counterpart to the access to the source code and  rights to copy,
    1.26 + #  modify and redistribute granted by the license, users are provided only
    1.27 + #  with a limited warranty  and the software's author,  the holder of the
    1.28 + #  economic rights,  and the successive licensors  have only  limited
    1.29 + #  liability.
    1.30 + #
    1.31 + #  In this respect, the user's attention is drawn to the risks associated
    1.32 + #  with loading,  using,  modifying and/or developing or reproducing the
    1.33 + #  software by the user in light of its specific status of free software,
    1.34 + #  that may mean  that it is complicated to manipulate,  and  that  also
    1.35 + #  therefore means  that it is reserved for developers  and  experienced
    1.36 + #  professionals having in-depth computer knowledge. Users are therefore
    1.37 + #  encouraged to load and test the software's suitability as regards their
    1.38 + #  requirements in conditions enabling the security of their systems and/or
    1.39 + #  data to be ensured and,  more generally, to use and operate it in the
    1.40 + #  same conditions as regards security.
    1.41 + #
    1.42 + #  The fact that you are presently reading this means that you have had
    1.43 + #  knowledge of the CeCILL license and that you accept its terms.
    1.44 + #
    1.45 +*/
    1.46 +
    1.47 +#ifndef cimg_plugin_noise_analysis
    1.48 +#define cimg_plugin_noise_analysis
    1.49 +
    1.50 +//! Compute somme pseudo-residuals
    1.51 +/*
    1.52 +  The pseudo residual r_i of the image Y_i are so thar E[r_i^2] = E[Y_i^2].
    1.53 +  This is the 2D pseudo-implementation.
    1.54 +*/
    1.55 +CImg<float> get_pseudo_residuals() const {
    1.56 +  CImg<float> residu(dimx(),dimy(),dimz(),dim);
    1.57 +  if (!is_empty()){
    1.58 +    cimg_forXYZV(*this,x,y,z,v) {
    1.59 +      double t2 = 0;
    1.60 +      if (x==0) t2+=(*this)(x+1,y,z,v);
    1.61 +      else t2+=(*this)(x-1,y,z,v);
    1.62 +      if ((unsigned int)x==(unsigned int)(dimx()-1)) t2+=(*this)(x-1,y,z,v);
    1.63 +      else t2+=(*this)(x+1,y,z,v);
    1.64 +      if (y==0) t2+=(*this)(x,y+1,z,v);
    1.65 +      else t2+=(*this)(x,y-1,z,v);
    1.66 +      if ((unsigned int)y==(unsigned int)(dimy()-1)) t2+=(*this)(x,y-1,z,v);
    1.67 +      else t2+=(*this)(x,y+1,z,v);
    1.68 +      residu(x,y,z,v) = (float)(0.223606798*(4.*(double)(*this)(x,y,z,v)-t2));
    1.69 +    }
    1.70 +  }
    1.71 +  return residu;
    1.72 +}
    1.73 +
    1.74 +//! Estimate the noise variance
    1.75 +/*
    1.76 +  \param method = 0 : Least Median of Square,
    1.77 +                  1 : Least Trimmed of Square,
    1.78 +                  2 : Least Mean of Square.
    1.79 +   Robustly estimatate the variance of a the noise using the pseudo-residuals.
    1.80 +   \see variance_estimation()
    1.81 +*/
    1.82 +double noise_variance(const unsigned int method=0) const {
    1.83 +  return (*this).get_pseudo_residuals().variance(method);
    1.84 +}
    1.85 +
    1.86 +#endif