🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.image.processing
Article #121

Canny Edge Detector

#121
From: S A J Winder
Date: Thu, 06 Aug 1992 21:12
78 lines
4242 bytes
In reply to: colaluca@cs.utexas.edu (Mark Colaluca)

> I am working on using a Canny Edge Operator to detect image edges...

> Also, if anyone has experience using the Canny operator, I'd appreciate
> your comments, suggestions, etc.

Here's how I have implemented the basic Canny edge operator. This may
be of use to a few people...

1. Smooth the image with a Gaussian kernel. This has the form:
   G(r) = 1/(2*pi*sigma*sigma) * exp(-r*r/(2*sigma)) for the 2D case,
   where sigma is the smoothing factor. You can do this in two 1D
   operations with G(x) = 1/(sigma*sqrt(2*pi)) * exp(-x*x/(2*sigma))
   -- first smooth horizontally, then smooth the result vertically.
*  NOTE: this smoothed result must be stored in floating point format
   otherwise you will get crazy results when you apply the second
   derivative operator!

2. Compute the gradient magnitude of the smoothed image. This is used
   later to validate edge segments. Compute the second derivative in
   the direction of the gradient vector. This function passes through
   zero at the position of each edge (you hope!) Here's some code to do
   this inside an xy loop:

     aa = smoothed_image(x-1,y-1);     /* Insert you're own   */
     bb = smoothed_image(x,y-1);       /* favourite method of */
     cc = smoothed_image(x+1,y-1);     /* getting at pixels   */
     dd = smoothed_image(x-1,y);
     ee = smoothed_image(x,y);
     ff = smoothed_image(x+1,y);
     gg = smoothed_image(x-1,y+1);     /* Note all variables  */
     hh = smoothed_image(x,y+1);       /* are floating point  */
     ii = smoothed_image(x+1,y+1);
     dfdx = ff-dd;                     /* Scaling factors omitted */
     dfdy = bb-hh;
     dfdxs = dfdx*dfdx;
     dfdys = dfdy*dfdy;
     gradient_magnitude = sqrt(dfdxs+dfdys);
     canny_function = (dd+ff-2.0*ee)*dfdxs+(bb+hh-2.0*ee)*dfdys+
                        (cc+gg-aa-ii)*dfdx*dfdy/2.0;

*  NOTE: the normalisation is omitted for the derivative and Canny
   functions because the former is subject to dynamic thresholding
   and the latter is used only to provide zero-crossing information.

3. Next make a bitmap image, setting pixels to one wherever
   canny_function>0.0 to get a two-value image whose region boundaries
   correspond to edge positions. You can then convert this into a
   binary edge map by comparing pixels within a neighbourhood. Every
   possible edge that could be detected at one scale using Canny's
   method is represented in such a map.
*  NOTE: I have never had canny_function return a value of 0.0 for real
   images---rather it alternates between large positive and negative values.
   Also "phantom edges" are removed by the thresholding stage...

4. Implement Canny's two-level thresholding technique: you need to
   decide on two suitable threshold values to apply to the gradient
   magnitude image you computed earlier. This is best done automatically
   with reference to the range of gradient values found from the image.
   Fixed thresholds fail to cater for changes in image contrast and
   smoothing factor.
      For every edge point detected in (3), check the gradient
   magnitude at the same point against the two thresholds. Produce a
   high-threshold edge map and a low-threshold edge map. The high-threshold
   map will have the major edges and the low-threshold map will have these
   plus some more detail and unwanted edges.
      To complete the edge synthesis computation you need to write an
   algorithm that walks along all the high-threshold edges copying them
   onto another bitmap together with any connected edges in the low-
   threshold map.

Simon.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Simon A.J. Winder                 Computer Vision Research
 sajw@uk.ac.bath.maths                University of Bath
 Tel: +44 (0)225 826183            /\/\/\/\/\/\/\/\/\/\/\/\
Technical Details
Message-ID: <1992Aug6.211246.9253@gdr.bath.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!unipalm!uknet!gdt!mapsajw

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!unipalm!uknet!gdt!mapsajw
From: mapsajw@gdr.bath.ac.uk (S A J Winder)
Newsgroups: sci.image.processing
Subject: Canny Edge Detector
Message-ID: <1992Aug6.211246.9253@gdr.bath.ac.uk>
Date: 6 Aug 92 21:12:46 GMT
Organization: Bath University Computing Group
Lines: 78