60#include "edtaa3func.h"
67void computegradient(
double *img,
int w,
int h,
double *gx,
double *gy)
71#define SQRT2 1.4142136
72 for(i = 1; i < h-1; i++) {
73 for(j = 1; j < w-1; j++) {
75 if((img[k]>0.0) && (img[k]<1.0)) {
76 gx[k] = -img[k-w-1] - SQRT2*img[k-1] - img[k+w-1] + img[k-w+1] + SQRT2*img[k+1] + img[k+w+1];
77 gy[k] = -img[k-w-1] - SQRT2*img[k-w] - img[k-w+1] + img[k+w-1] + SQRT2*img[k+w] + img[k+w+1];
78 glength = gx[k]*gx[k] + gy[k]*gy[k];
80 glength = sqrt(glength);
101double edgedf(
double gx,
double gy,
double a)
103 double df, glength, temp, a1;
105 if ((gx == 0) || (gy == 0)) {
108 glength = sqrt(gx*gx + gy*gy);
126 df = 0.5*(gx + gy) - sqrt(2.0*gx*gy*a);
127 }
else if (a < (1.0-a1)) {
130 df = -0.5*(gx + gy) + sqrt(2.0*gx*gy*(1.0-a));
136double distaa3(
double *img,
double *gximg,
double *gyimg,
int w,
int c,
int xc,
int yc,
int xi,
int yi)
138 double di, df, dx, dy, gx, gy, a;
148 if(a == 0.0)
return 1000000.0;
152 di = sqrt(dx*dx + dy*dy);
155 df = edgedf(gx, gy, a);
158 df = edgedf(dx, dy, a);
164#define DISTAA(c,xc,yc,xi,yi) (distaa3(img, gx, gy, w, c, xc, yc, xi, yi))
166void edtaa3(
double *img,
double *gx,
double *gy,
int w,
int h,
short *distx,
short *disty,
double *dist)
169 int offset_u, offset_ur, offset_r, offset_rd,
170 offset_d, offset_dl, offset_l, offset_lu;
171 double olddist, newdist;
172 int cdistx, cdisty, newdistx, newdisty;
174 double epsilon = 1e-3;
187 for(i=0; i<w*h; i++) {
194 else if (img[i]<1.0) {
195 dist[i] = edgedf(gx[i], gy[i], img[i]);
225 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
226 if(newdist < olddist-epsilon)
240 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
241 if(newdist < olddist-epsilon)
252 for(x=1; x<w-1; x++, i++)
255 if(olddist <= 0)
continue;
262 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
263 if(newdist < olddist-epsilon)
277 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
278 if(newdist < olddist-epsilon)
292 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
293 if(newdist < olddist-epsilon)
307 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
308 if(newdist < olddist-epsilon)
326 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
327 if(newdist < olddist-epsilon)
341 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
342 if(newdist < olddist-epsilon)
356 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
357 if(newdist < olddist-epsilon)
371 for(x=w-2; x>=0; x--, i--)
374 if(olddist <= 0)
continue;
381 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
382 if(newdist < olddist-epsilon)
393 for(y=h-2; y>=0; y--)
409 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
410 if(newdist < olddist-epsilon)
424 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
425 if(newdist < olddist-epsilon)
436 for(x=w-2; x>0; x--, i--)
439 if(olddist <= 0)
continue;
446 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
447 if(newdist < olddist-epsilon)
461 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
462 if(newdist < olddist-epsilon)
476 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
477 if(newdist < olddist-epsilon)
491 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
492 if(newdist < olddist-epsilon)
509 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
510 if(newdist < olddist-epsilon)
524 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
525 if(newdist < olddist-epsilon)
539 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
540 if(newdist < olddist-epsilon)
552 for(x=1; x<w; x++, i++)
556 if(olddist <= 0)
continue;
563 newdist = DISTAA(
c, cdistx, cdisty, newdistx, newdisty);
564 if(newdist < olddist-epsilon)