00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 }