Wed, 05 Aug 2009 17:32:05 +0100
updated README
1 /*
2 #
3 # File : noise_analysis.h
4 # ( C++ header file - CImg plug-in )
5 #
6 # Description : CImg plug-in that estimates noise standard deviation.
7 # This file is a part of the CImg Library project.
8 # ( http://cimg.sourceforge.net )
9 #
10 # Copyright : Jerome Boulanger
11 # ( http://www.irisa.fr/vista/Equipe/People/Jerome.Boulanger.html )
12 #
13 # License : CeCILL v2.0
14 # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
15 #
16 # This software is governed by the CeCILL license under French law and
17 # abiding by the rules of distribution of free software. You can use,
18 # modify and/ or redistribute the software under the terms of the CeCILL
19 # license as circulated by CEA, CNRS and INRIA at the following URL
20 # "http://www.cecill.info".
21 #
22 # As a counterpart to the access to the source code and rights to copy,
23 # modify and redistribute granted by the license, users are provided only
24 # with a limited warranty and the software's author, the holder of the
25 # economic rights, and the successive licensors have only limited
26 # liability.
27 #
28 # In this respect, the user's attention is drawn to the risks associated
29 # with loading, using, modifying and/or developing or reproducing the
30 # software by the user in light of its specific status of free software,
31 # that may mean that it is complicated to manipulate, and that also
32 # therefore means that it is reserved for developers and experienced
33 # professionals having in-depth computer knowledge. Users are therefore
34 # encouraged to load and test the software's suitability as regards their
35 # requirements in conditions enabling the security of their systems and/or
36 # data to be ensured and, more generally, to use and operate it in the
37 # same conditions as regards security.
38 #
39 # The fact that you are presently reading this means that you have had
40 # knowledge of the CeCILL license and that you accept its terms.
41 #
42 */
44 #ifndef cimg_plugin_noise_analysis
45 #define cimg_plugin_noise_analysis
47 //! Compute somme pseudo-residuals
48 /*
49 The pseudo residual r_i of the image Y_i are so thar E[r_i^2] = E[Y_i^2].
50 This is the 2D pseudo-implementation.
51 */
52 CImg<float> get_pseudo_residuals() const {
53 CImg<float> residu(dimx(),dimy(),dimz(),dim);
54 if (!is_empty()){
55 cimg_forXYZV(*this,x,y,z,v) {
56 double t2 = 0;
57 if (x==0) t2+=(*this)(x+1,y,z,v);
58 else t2+=(*this)(x-1,y,z,v);
59 if ((unsigned int)x==(unsigned int)(dimx()-1)) t2+=(*this)(x-1,y,z,v);
60 else t2+=(*this)(x+1,y,z,v);
61 if (y==0) t2+=(*this)(x,y+1,z,v);
62 else t2+=(*this)(x,y-1,z,v);
63 if ((unsigned int)y==(unsigned int)(dimy()-1)) t2+=(*this)(x,y-1,z,v);
64 else t2+=(*this)(x,y+1,z,v);
65 residu(x,y,z,v) = (float)(0.223606798*(4.*(double)(*this)(x,y,z,v)-t2));
66 }
67 }
68 return residu;
69 }
71 //! Estimate the noise variance
72 /*
73 \param method = 0 : Least Median of Square,
74 1 : Least Trimmed of Square,
75 2 : Least Mean of Square.
76 Robustly estimatate the variance of a the noise using the pseudo-residuals.
77 \see variance_estimation()
78 */
79 double noise_variance(const unsigned int method=0) const {
80 return (*this).get_pseudo_residuals().variance(method);
81 }
83 #endif