/home/neoflo/smb4k/SERVEUR/Millie/trunk/src/PredefinedKernel.cpp

Aller à la documentation de ce fichier.
00001 /******************************************************************************
00002  *       __    _    _   _       _       _   _____                             *
00003  *       | \  / |  | | | |     | |     | |  | ___|                            *
00004  *       |  \/  |  | | | |     | |     | |  | |_                              *
00005  *       |      |  | | | |     | |     | |  |  _|                             *
00006  *       | |\/| |  | | | |__   | |__   | |  | |__                             *
00007  *       |_|  |_|  |_| |____|  |____|  |_|  |____|                            *
00008  * __________________________________________________________________________ *
00009  *                 Multifunctional Library For Image Processing               *
00010  *                                                                            *
00011  *                                                                            *
00012  *                                                                            *
00013  *      (c) Copyright 2007 by Humbert Florent                                 *
00014  *                                                                            *
00015  *      This program is free software; you can redistribute it and/or modify  *
00016  *      it under the terms of the GNU General Public License as published by  *
00017  *      the Free Software Foundation; only version 2 of the License.          *
00018  *                                                                            *
00019  *      This program is distributed in the hope that it will be useful,       *
00020  *      but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *      GNU General Public License for more details.                          *
00023  *                                                                            *
00024  *      You should have received a copy of the GNU General Public License     *
00025  *      along with this program; if not, write to the Free Software           *
00026  *      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA             *
00027  *      02111-1307, USA.                                                      *
00028  ******************************************************************************/
00029 
00032 #include <cmath>
00033 
00034 #include "PredefinedKernel.hpp"
00035 
00036 using namespace Millie;
00037 
00038 static const float floatSobelVerticalKernel [] =
00039   {
00040     -1, -2 , -1,
00041     0,  0,   0,
00042     1,  2,   1
00043   };
00044 
00045 static const float floatSobelHorizontalKernel []=
00046   {
00047     -1, 0, 1,
00048     -2, 0, 2,
00049     -1, 0, 1
00050   };
00051 
00052 static const float floatPrewittVerticalKernel [] =
00053   {
00054     -1, -1 , -1,
00055     0,  0,   0,
00056     1,  1,   1
00057   };
00058 
00059 static const float floatPrewittHorizontalKernel []=
00060   {
00061     -1, 0, 1,
00062     -1, 0, 1,
00063     -1, 0, 1
00064   };
00065 
00066 
00067 static const float floatLaplaceKernel [] =
00068   {
00069     0, 1, 0,
00070     1,  -4, 1,
00071     0, 1, 0
00072   };
00073 
00074 static const float floatMDIFKernel []  =
00075   {
00076     0, 1, 0, -1, 0,
00077     1, 2, 0, -2, -1,
00078     1, 3, 0, -3, -1,
00079     1, 2, 0, -2, -1,
00080     0, 1, 0, -1, 0
00081   };
00082 
00083 static const float floatMediumSmoothKernel [] =
00084   {
00085     1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f,
00086     1.0f / 9.0f,1.0f / 9.0f,1.0f / 9.0f,
00087     1.0f / 9.0f,1.0f / 9.0f,1.0f / 9.0f
00088   };
00089 
00090 KernelSobelVertical::KernelSobelVertical()
00091     :
00092     Kernel(3,3,1,1, floatSobelVerticalKernel)
00093 {}
00094 
00095 KernelSobelHorizontal::KernelSobelHorizontal()
00096     : Kernel(3,3 ,1,1, floatSobelHorizontalKernel)
00097 {}
00098 
00099 KernelPrewittVertical::KernelPrewittVertical()
00100     : Kernel(3,3,1,1, floatPrewittVerticalKernel)
00101 {}
00102 
00103 KernelPrewittHorizontal::KernelPrewittHorizontal()
00104     : Kernel(3,3 ,1,1, floatPrewittHorizontalKernel)
00105 {}
00106 
00107 KernelLaplace::KernelLaplace()
00108     : Kernel(3,3,1,1, floatLaplaceKernel)
00109 {}
00110 
00111 KernelMDIF::KernelMDIF()
00112     : Kernel(5,5,2,2, floatMDIFKernel)
00113 {}
00114 
00115 
00116 KernelMediumSmooth::KernelMediumSmooth()
00117     : Kernel(3,3,1,1, floatMediumSmoothKernel)
00118 {}
00119 
00120 
00121 
00122 KernelGaussian::KernelGaussian(int rayon, double sigma)
00123     : Kernel(2*rayon+1,2*rayon+1,rayon,rayon)
00124 {
00125   if(sigma <0.0f)
00126     throw IllegalArgument("KernelGaussian : sigma negative");
00127 
00128   float gaussianKernelFactor=0;
00129 
00130   for(int ky=-rayon;ky<=rayon;ky++)
00131   {
00132     for(int kx=-rayon;kx<=rayon;kx++)
00133     {
00134       float e = exp( - (kx*kx+ky*ky) / (2*sigma*sigma) );
00135       gaussianKernelFactor += e;
00136       setValue(kx+rayon, ky+rayon, e);
00137     }
00138   }
00139 
00140   for(int ky = 0; ky< getHeight(); ky++)
00141    for(int kx = 0; kx < getWidth(); kx++) {
00142       float valeur = (*this)(kx,ky);
00143       setValue(kx, ky, valeur/ gaussianKernelFactor);
00144    }
00145 
00146 }

Généré le Fri May 18 23:24:46 2007 pour Millie par  doxygen 1.5.1