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 "DifferentialOperators.hpp"
00033 #include "MillieStd.hpp"
00034
00035 using namespace Millie;
00036
00037
00038
00039
00040
00041 float Millie::diffDx(const Image& in, int x, int y, int canal)
00042 {
00043 int width = in.getWidth();
00044
00045 int px = x-1;
00046 int nx = x+1;
00047 if (px<0)
00048 px=0;
00049 if (nx>=width)
00050 nx=width-1;
00051
00052 return((in.getPixel(nx,y,canal) - in.getPixel(px,y,canal))/2.0f);
00053 }
00054
00055 float Millie::diffDxminmod(const Image & in, int x, int y, int canal)
00056 {
00057 float fx= 0.0f;
00058
00059 float dplus= diffDxP(in, x, y, canal);
00060 float dmoins= diffDxN(in, x, y, canal);
00061
00062 fx= Math::minmod( dmoins, dplus );
00063
00064 return fx;
00065 }
00066
00067 float Millie::diffDyminmod(const Image & in, int x, int y, int canal)
00068 {
00069 float fy= 0.0f;
00070
00071 float dmoins= diffDyP(in, x, y, canal);
00072 float dplus= diffDyN(in, x, y, canal);
00073
00074 fy= Math::minmod( dmoins, dplus );
00075
00076 return fy;
00077 }
00078
00079 float Millie::diffDxN(const Image & in, int x, int y, int canal)
00080 {
00081 int width = in.getWidth();
00082 if (x+1>=width)
00083 return 0;
00084
00085 return(in.getPixel(x+1, y, canal) - in.getPixel(x,y,canal));
00086 }
00087
00088 float Millie::diffDxP(const Image & in, int x, int y, int canal)
00089 {
00090 if(x-1<0)
00091 return 0;
00092 return(in.getPixel(x, y, canal) - in.getPixel(x-1,y,canal));
00093 }
00094
00095 float Millie::diffDy(const Image& in, int x, int y, int canal)
00096 {
00097 int height = in.getHeight();
00098
00099 int py = y-1;
00100 int ny = y+1;
00101
00102 if (py<0)
00103 py=0;
00104 if (ny>=height)
00105 ny=height-1;
00106
00107 return (in.getPixel(x,ny,canal) - in.getPixel(x,py,canal))/2.0f;
00108 }
00109
00110 float Millie::diffDyN(const Image & in, int x, int y, int canal)
00111 {
00112 int height = in.getHeight();
00113 if (y+1>=height)
00114 return 0;
00115
00116 return(in.getPixel(x, y+1, canal) - in.getPixel(x,y,canal));
00117 }
00118
00119 float Millie::diffDyP(const Image & in, int x, int y, int canal)
00120 {
00121 if(y-1<0)
00122 return 0;
00123 return(in.getPixel(x, y, canal) - in.getPixel(x,y-1,canal));
00124 }
00125
00126 float Millie::diffDxx(const Image& in, int x, int y, int canal)
00127 {
00128 int width = in.getWidth();
00129
00130 int px = x-1;
00131 int nx = x+1;
00132 if (px<0)
00133 px=0;
00134 if (nx>=width)
00135 nx=width-1;
00136 return (in.getPixel(nx,y,canal) + in.getPixel(px,y,canal) -2.0f * in.getPixel(x,y, canal));
00137 }
00138
00139
00140 float Millie::diffDyy(const Image& in, int x, int y, int canal)
00141 {
00142 int height = in.getHeight();
00143
00144 int py = y-1;
00145 int ny = y+1;
00146
00147 if (py<0)
00148 py=0;
00149 if (ny>=height)
00150 ny=height-1;
00151
00152 return (in.getPixel(x,ny,canal) + in.getPixel(x,py,canal) -2.0f * in.getPixel(x,y, canal));
00153 }
00154
00155
00156
00157 float Millie::diffDnnC(const Image& in, int x, int y, int canal)
00158 {
00159 float fx = diffDx(in, x,y, canal);
00160 float fy = diffDy(in, x,y, canal);
00161
00162
00163 float squareGradN = diffSquareGradN(in, x,y, canal);
00164
00165
00166 float fx_grad_carre;
00167 float fy_grad_carre;
00168 float fxy_grad_carre;
00169
00170
00171 fx_grad_carre = (fx * fx)/ squareGradN;
00172 fy_grad_carre = (fy * fy) / squareGradN;
00173 fxy_grad_carre = (fx * fy) / squareGradN;
00174
00175
00176 float lambda0 = 0.5;
00177 float lambda1 = 2.0*lambda0 - fx_grad_carre;
00178 float lambda2 = 2.0*lambda0 - fy_grad_carre;
00179 float lambda3 = 0.5 * (-fxy_grad_carre + 1.0 - (2.0 * lambda0));
00180 float lambda4 = 0.5 * (1.0 - (2.0 * lambda0) + fxy_grad_carre);
00181
00182 int width = in.getWidth();
00183 int height = in.getHeight();
00184
00185 int px = x-1;
00186 int nx = x+1;
00187 int py = y-1;
00188 int ny = y+1;
00189 if (px<0)
00190 px=0;
00191 if (nx>=width)
00192 nx=width-1;
00193 if (py<0)
00194 py=0;
00195 if (ny>=height)
00196 ny=height-1;
00197
00198 return (( lambda4 * in.getPixel(px,py, canal)
00199 + lambda2 * in.getPixel(x ,py, canal)
00200 + lambda3 * in.getPixel(nx,py, canal)
00201 + lambda1 * in.getPixel(px,y, canal)
00202 - 4 * lambda0 * in.getPixel(x ,y, canal)
00203 + lambda1 * in.getPixel(nx,y, canal)
00204 + lambda3 * in.getPixel(px,ny, canal)
00205 + lambda2 * in.getPixel(x ,ny, canal)
00206 + lambda4 * in.getPixel(nx,ny, canal)));
00207
00208 }
00209
00210 float Millie::diffDntntC(const Image& in, int x, int y, int canal)
00211 {
00212 float fx = diffDx(in, x,y, canal);
00213 float fy = diffDy(in, x,y, canal);
00214
00215
00216
00217 float squareGradN = diffSquareGradN(in, x, y, canal);
00218
00219
00220 float fx_grad_carre;
00221 float fy_grad_carre;
00222 float fxy_grad_carre;
00223
00224 if(squareGradN<0.01f)
00225 return 0;
00226
00227 fx_grad_carre = (fx * fx)/ squareGradN ;
00228 fy_grad_carre = (fy * fy) / squareGradN ;
00229 fxy_grad_carre = (fx * fy) / squareGradN ;
00230
00231
00232 float lambda0 = 0.5;
00233 float lambda1 = 2.0*lambda0 - fx_grad_carre;
00234 float lambda2 = 2.0*lambda0 - fy_grad_carre;
00235 float lambda3 = 0.5 * (-fxy_grad_carre + 1.0 - (2.0 * lambda0));
00236 float lambda4 = 0.5 * (1.0 - (2.0 * lambda0) + fxy_grad_carre);
00237
00238 int width = in.getWidth();
00239 int height = in.getHeight();
00240
00241 int px = x-1;
00242 int nx = x+1;
00243 int py = y-1;
00244 int ny = y+1;
00245 if (px<0)
00246 px=0;
00247 if (nx>=width)
00248 nx=width-1;
00249 if (py<0)
00250 py=0;
00251 if (ny>=height)
00252 ny=height-1;
00253
00254 return (( lambda4 * in.getPixel(px,py, canal)
00255 + lambda2 * in.getPixel(x ,py, canal)
00256 + lambda3 * in.getPixel(nx,py, canal)
00257 + lambda1 * in.getPixel(px,y, canal)
00258 - 4 * lambda0 * in.getPixel(x ,y, canal)
00259 + lambda1 * in.getPixel(nx,y, canal)
00260 + lambda3 * in.getPixel(px,ny, canal)
00261 + lambda2 * in.getPixel(x ,ny, canal)
00262 + lambda4 * in.getPixel(nx,ny, canal)));
00263 }
00264
00265
00266 float Millie::diffDxy(const Image& in, int x, int y, int canal)
00267 {
00268 int width = in.getWidth();
00269 int height = in.getHeight();
00270
00271 int px = x-1;
00272 int nx = x+1;
00273 int py = y-1;
00274 int ny = y+1;
00275 if (px<0)
00276 px=0;
00277 if (nx>=width)
00278 nx=width-1;
00279 if (py<0)
00280 py=0;
00281 if (ny>=height)
00282 ny=height-1;
00283
00284 return 0.25 * (in.getPixel(nx, ny, canal) + in.getPixel(px, py, canal)
00285 - in.getPixel(px, ny, canal) - in.getPixel(nx, py, canal));
00286 }
00287
00288
00289
00290 float Millie::diffGradN(const Image& in, int x, int y, int canal)
00291 {
00292 return std::sqrt(Math::square(diffDx(in, x, y, canal)) + Math::square(diffDy(in, x, y, canal)));
00293 }
00294
00295 float Millie::diffGradNminmod(const Image& in, int x, int y, int canal)
00296 {
00297 return sqrt(Math::square(diffDxminmod(in, x, y, canal)) + Math::square(diffDyminmod(in, x, y, canal)));
00298 }
00299
00300 float Millie::diffLaplace(const Image& in, int x, int y, int canal)
00301 {
00302 return(diffDxx(in, x, y, canal) + diffDyy(in, x, y, canal));
00303 }
00304
00305 float Millie::diffSquareGradN(const Image& in, int x, int y, int canal)
00306 {
00307 return Math::square(diffDx(in, x, y, canal)) + Math::square(diffDy(in, x, y, canal));
00308 }
00309
00310 float Millie::diffDnn(const Image& in, int x, int y, int canal)
00311 {
00312 float norme = diffSquareGradN(in, x,y, canal);
00313
00314
00315
00316 float dx = diffDx(in, x, y, canal);
00317 float dy = diffDy(in, x, y, canal);
00318 float dxx = diffDxx(in, x, y, canal);
00319 float dyy = diffDyy(in, x, y, canal);
00320 float dxy = diffDxy(in, x, y, canal);
00321 float temp =Math::square(dx) * dxx +Math::square(dy) * dyy
00322 + 2.0 * dx * dy * dxy;
00323 return (temp/(norme+1e-8));
00324 }
00325
00326
00327
00328 float Millie::diffDntnt(const Image& in, int x, int y, int canal)
00329 {
00330 float norme = diffSquareGradN(in, x,y, canal);
00331 if(norme<0.001f)
00332 return 0.0f;
00333
00334 float dx = diffDx(in, x, y, canal);
00335 float dy = diffDy(in, x, y, canal);
00336 float dxx = diffDxx(in, x, y, canal);
00337 float dyy = diffDyy(in, x, y, canal);
00338 float dxy = diffDxy(in, x, y, canal);
00339 float temp = Math::square(dx) * dxx + Math::square(dy) * dyy
00340 - 2.0 * dx * dy * dxy;
00341 return (temp/norme);
00342 }
00343
00344
00345
00346