Page 94 -
P. 94

68    Chapter 2 ■ Edge-Detection Techniques



                                        {
                                          if (g*MAG_SCALE <= 255)
                                          mag->data[i][j] = (unsigned char)(g*MAG_SCALE);
                                          else
                                          mag->data[i][j] = 255;
                                        ori->data[i][j] = (unsigned char) (atan2 (yc, xc) * ORI_SCALE);
                                        } else
                                        {
                                          mag->data[i][j] = 0;
                                          ori->data[i][j] = 0;
                                        }

                                      }
                                    }
                             }
                             void estimate_thresh (IMAGE mag, int *hi, int *low)
                             {
                                    int i,j,k, hist[256], count;

                             /* Build a histogram of the magnitude image. */
                                    for (k=0; k<256; k++) hist[k] = 0;

                                    for (i=WIDTH; i<mag->info->nr-WIDTH; i++)
                                      for (j=WIDTH; j<mag->info->nc-WIDTH; j++)
                                        hist[mag->data[i][j]]++;

                             /* The high threshold should be > 80 or 90% of the pixels
                                    j = (int)(ratio*mag->info->nr*mag->info->nc);
                             */
                                    j = mag->info->nr;
                                    if (j<mag->info->nc) j = mag->info->nc;
                                    j = (int)(0.9*j);
                                    k = 255;

                                    count = hist[255];
                                    while (count < j)
                                    {
                                      k--;
                                      if (k<0) break;
                                      count += hist[k];
                                    }
                                    *hi = k;

                                    i=0;
                                    while (hist[i]==0) i++;

                                    *low = (*hi+i)/2.0f;
                             }
   89   90   91   92   93   94   95   96   97   98   99