Page 104 -
P. 104

78    Chapter 2 ■ Edge-Detection Techniques



                             void estimate_thresh (double *low, double *hi, int nr, int nc)
                             {
                                    float vmax, vmin, scale, x;
                                    int i,j,k, hist[256], count;
                             /* Build a histogram of the Laplacian image. */
                                    vmin = vmax = fabs((float)(lap[20][20]));
                                    for (i=0; i<nr; i++)
                                      for (j=0; j<nc; j++)
                                      {
                                         if (i<OUTLINE || i >= nr-OUTLINE ||
                                              j<OUTLINE || j >= nc-OUTLINE) continue;
                                        x = lap[i][j];
                                        if (vmin > x) vmin = x;
                                        if (vmax < x) vmax = x;
                                      }
                                    for (k=0; k<256; k++) hist[k] = 0;

                                    scale = 256.0/(vmax-vmin + 1);

                                    for (i=0; i<nr; i++)
                                      for (j=0; j<nc; j++)
                                      {
                                         if (i<OUTLINE || i >= nr-OUTLINE ||
                                              j<OUTLINE || j >= nc-OUTLINE) continue;
                                        x = lap[i][j];
                                        k = (int)((x - vmin)*scale);
                                        hist[k] += 1;
                                      }

                             /* The high threshold should be > 80 or 90% of the pixels */
                                    k = 255;
                                    j = (int)(ratio*nr*nc);
                                    count = hist[255];
                                    while (count < j)
                                    {
                                      k--;
                                      if (k<0) break;
                                      count += hist[k];
                                    }
                                    *hi = (double)k/scale  + vmin ;
                                    *low = (*hi)/2;
                             }
                             void embed (IMAGE im, int width)
                             {
                                    int i,j,I,J;
                                    IMAGE new;
                                    width += 2;
   99   100   101   102   103   104   105   106   107   108   109