48#include "edtaa3func.h"
63 short * xdist = (
short *) malloc( width * height *
sizeof(
short) );
64 short * ydist = (
short *) malloc( width * height *
sizeof(
short) );
65 double * gx = (
double *) calloc( width * height,
sizeof(
double) );
66 double * gy = (
double *) calloc( width * height,
sizeof(
double) );
67 double * outside = (
double *) calloc( width * height,
sizeof(
double) );
68 double * inside = (
double *) calloc( width * height,
sizeof(
double) );
72 computegradient( data, width, height, gx, gy);
73 edtaa3(data, gx, gy, width, height, xdist, ydist, outside);
74 for( i=0; i<width*height; ++i)
75 if( outside[i] < 0.0 )
79 memset( gx, 0,
sizeof(
double)*width*height );
80 memset( gy, 0,
sizeof(
double)*width*height );
81 for( i=0; i<width*height; ++i)
82 data[i] = 1 - data[i];
83 computegradient( data, width, height, gx, gy );
84 edtaa3( data, gx, gy, width, height, xdist, ydist, inside );
85 for( i=0; i<width*height; ++i )
91 for( i=0; i<width*height; ++i)
93 outside[i] -= inside[i];
94 if( *vmax < fabs( outside[i] ) )
95 *vmax = fabs( outside[i] );
98 for( i=0; i<width*height; ++i)
100 double v = outside[i];
101 if ( v < -*vmax) outside[i] = -*vmax;
102 else if( v > +*vmax) outside[i] = +*vmax;
103 data[i] = (outside[i]+*vmax)/(2. * *vmax);
129 unsigned int width,
unsigned int height,
double *vmax )
131 double * data = (
double *) calloc( width * height,
sizeof(
double) );
132 float *out = (
float *) malloc( width * height *
sizeof(
float) );
136 double img_min = DBL_MAX;
137 double img_max = DBL_MIN;
139 for( i=0; i<width*height; ++i)
150 for( i=0; i<width*height; ++i)
151 data[i] = (img[i]-img_min)/img_max;
156 for( i=0; i<width*height; ++i)
157 out[i] = (
float)(1-data[i]);
float * make_distance_mapbf(unsigned char *img, unsigned int width, unsigned int height, double *vmax)
Perform a Euclidean Distance Transform on the input and normalize to [0,1], with a value of 0....
double * make_distance_mapd(double *data, unsigned int width, unsigned int height, double *vmax)
Like the original: perform a Euclidean Distance Transform on the input and normalize to [0,...