Page 101 -
P. 101
Chapter 2 ■ Edge-Detection Techniques 75
nr = nrows;
nc = ncols;
estimate_thresh (&low_thresh, &high_thresh, nr, nc);
if (!do_hysteresis)
low_thresh = high_thresh;
for (i=0; i<nrows; i++)
for (j=0; j<ncols; j++)
edges->data[i][j] = 0;
for (i=0; i<nrows; i++)
for (j=0; j<ncols; j++)
{
if (i<OUTLINE || i >= nrows-OUTLINE ||
j<OUTLINE || j >= ncols-OUTLINE) continue;
/* only check a contour if it is above high_thresh */
if ((lap[i][j]) > high_thresh)
/* mark all connected points above low thresh */
mark_connected (i,j,0);
}
for (i=0; i<nrows; i++) /* erase all points which were 255 */
for (j=0; j<ncols; j++)
if (edges->data[i][j] == 255) edges->data[i][j] = 0;
}
/* return true if it marked something */
int mark_connected (int i, int j, int level)
{
int notChainEnd;
/* stop if you go off the edge of the image */
if (i >= nr || i < 0 || j >= nc || j < 0) return 0;
/* stop if the point has already been visited */
if (edges->data[i][j] != 0) return 0;
/* stop when you hit an image boundary */
if (lap[i][j] == 0.0) return 0;
if ((lap[i][j]) > low_thresh)
{
edges->data[i][j] = 1;
}
else
{
edges->data[i][j] = 255;
}