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