PTdecode/CImg-1.3.0/plugins/noise_analysis.h

Fri, 25 Sep 2009 10:50:44 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Fri, 25 Sep 2009 10:50:44 +0100
changeset 21
629637abfe1f
parent 5
1204ebf9340d
permissions
-rwxr-xr-x

added dots-per-inch to status readback

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