Page 89 -
P. 89
Chapter 2 ■ Edge-Detection Techniques 63
dgau[i] = dGauss ((float)i, s);
}
n = width+width + 1;
WIDTH = width/2;
printf (“Smoothing with a Gaussian (width = %d) ...\n“, n);
smx = f2d (im->info->nr, im->info->nc);
smy = f2d (im->info->nr, im->info->nc);
/* Convolution of source image with a Gaussian in X and Y directions */
seperable_convolution (im, gau, width, smx, smy);
/* Now convolve smoothed data with a derivative */
printf (“Convolution with the derivative of a Gaussian...\n“);
dx = f2d (im->info->nr, im->info->nc);
dxy_seperable_convolution (smx, im->info->nr, im->info->nc,
dgau, width, dx, 1);
free(smx[0]); free(smx);
dy = f2d (im->info->nr, im->info->nc);
dxy_seperable_convolution (smy, im->info->nr, im->info->nc,
dgau, width, dy, 0);
free(smy[0]); free(smy);
/* Create an image of the norm of dx,dy */
for (i=0; i<im->info->nr; i++)
for (j=0; j<im->info->nc; j++)
{
z = norm (dx[i][j], dy[i][j]);
mag->data[i][j] = (unsigned char)(z*MAG_SCALE);
}
/* Non-maximum suppression - edge pixels should be a local max */
nonmax_suppress (dx, dy, (int)im->info->nr,(int)im->info->nc, mag, ori);
free(dx[0]); free(dx);
free(dy[0]); free(dy);
}
/* Gaussian */
float gauss(float x, float sigma)
{
float xx;
if (sigma == 0) return 0.0;
xx = (float)exp((double) ((-x*x)/(2*sigma*sigma)));
return xx;