Page 84 -
P. 84

58    Chapter 2 ■ Edge-Detection Techniques


                             The hue is actually an angle from 0 (red) to the color being specified. This
                           makes hue a pure color coordinate, and could be used to detect edges. Figure
                           2.19b is the simple color image of 2.17a converted into hue and then run
                           through the Sobel edge detector. The edges have been thresholded, partly
                           because the horizontal ones correspond to transitions between similar colors,
                           and so are weaker than the vertical edges.



                           2.8    Source Code for the Marr-Hildreth
                           Edge Detector



                             /* Marr/Hildreth edge detection */

                             #include “stdio.h“
                             #include “cv.h“
                             #include “highgui.h“
                             #include <math.h>
                             #include “lib.h“

                             float norm (float x, float y)
                             {
                                    return (float) sqrt ( (double)(x*x + y*y) );
                             }
                             float distance (float a, float b, float c, float d)
                             {
                                    return norm ( (a-c), (b-d) );
                             }

                             void marr (float s, IMAGE im)
                             {
                                    int width;
                                    float **smx;
                                    int i,j,k,n;
                                    float **lgau, z;

                             /* Create a Gaussian and a derivative of Gaussian filter mask */
                                    width = 3.35*s + 0.33;
                                    n = width+width + 1;
                                    printf (“Smoothing with a Gaussian of size %dx%d\n“, n, n);
                                    lgau = f2d (n, n);
                                    for (i=0; i<n; i++)
                                      for (j=0; j<n; j++)
                                        lgau[i][j] = LoG (distance ((float)i, (float)j,
                                                 (float)width, (float)width), s);
   79   80   81   82   83   84   85   86   87   88   89