Detecting Edges

Detecting edges is another way to help extract features. Many edge detection methods use either directional or Laplacian filters. See Directional Filtering and Laplacian Filtering for more information on directional and Laplacian filters.

IDL contains the following edge detection routines:

See the individual filter descriptions in the IDL Reference Guide for more information on these operators. Morphological operators are used for more complex edge detection. See "Detecting Edges of Image Objects" in Chapter 9 for more information on these operators.

The results of these edge detection routines can be added or subtracted from the original image to enhance the contrast of the edges within that image. Edge detection results are also used to calculate masks. See "Masking Images" in Chapter 4 for more information on masks.

Edge Detection Example

The following example shows how to use each of the seven functions to detect edges within an image. This example uses the aerial view of New York City within the nyny.dat file in the examples/data directory. Complete the following steps for a detailed description of the process.

Example Code
The file for this example, detecting_edges_doc.pro, is located in the examples/doc/image subdirectory of the IDL distribution. Run the example procedure by entering detecting_edges_doc at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT detecting_edges_doc.pro.

  1. Read in image data from the binary file nyny.dat
  2. file = FILEPATH('nyny.dat', SUBDIRECTORY = ['examples',$ 
       'data']) 
    imageSize = [768, 512] 
    image = READ_BINARY(file, DATA_DIMS = imageSize) 
    
  3. Crop the image to focus on the bridges
  4. croppedSize = [96, 96] 
    croppedImage = image[200:(croppedSize[0] - 1) + 200, $ 
       180:(croppedSize[1] - 1) + 180] 
    
  5. Specify the size of the final displayed images
  6. displaySize = [150, 150] 
    
  7. Resize the image to the final display size, apply various detection filters, then display using iImage
  8. croppedImage = CONGRID(croppedImage, displaySize[0],$ 
       displaySize[1]) 
     
    IIMAGE, croppedImage, DIMENSIONS=[700,700], $ 
       VIEW_GRID=[4,2], $ 
       VIEW_TITLE='Original', /NO_SAVEPROMPT, $ 
       TITLE='Comparison of Edge Detection Filters' 
     
    robertsfilteredImage = ROBERTS(croppedImage) 
     
    IIMAGE, RobertsFilteredImage, /VIEW_NEXT , /OVERPLOT, $ 
       VIEW_TITLE='ROBERTS Filter' 
     
    SobelFilteredImage = SOBEL(croppedImage) 
     
    IIMAGE, SobelFilteredImage, /VIEW_NEXT, /OVERPLOT, $ 
       VIEW_TITLE='SOBEL Filter' 
     
    PrewittFilteredImage = PREWITT(croppedImage) 
     
    IIMAGE, PrewittFilteredImage, /VIEW_NEXT, /OVERPLOT, $ 
       VIEW_TITLE='PREWITT Filter' 
     
    ShiftDiffFilteredimage = SHIFT_DIFF(croppedImage) 
     
    IIMAGE, ShiftDiffFilteredimage, /VIEW_NEXT, /OVERPLOT, $ 
       VIEW_TITLE='SHIFT_DIFF Filter' 
     
    EdgeDogFilteredimage = EDGE_DOG(croppedImage) 
     
    IIMAGE, EdgeDogFilteredimage, /VIEW_NEXT, /OVERPLOT, $ 
       VIEW_TITLE='EDGE_DOG Filter' 
     
    LaplacianFilteredImage = LAPLACIAN(croppedImage) 
     
    IIMAGE, LaplacianFilteredImage, /VIEW_NEXT, /OVERPLOT, $ 
       VIEW_TITLE='LAPLACIAN Filter' 
     
    EmbossFilteredImage = EMBOSS(croppedImage) 
     
    IIMAGE, EmbossFilteredImage, /VIEW_NEXT, /OVERPLOT, $ 
       VIEW_TITLE='EMBOSS Filter'

    Figure 8-35: Each Filter Applied to the New York Image

    edge_detection_filters_01.gif