X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



7518 Rate this article:
4.0

Finding Straight Lines in Images with the IDL Hough Transform

This example uses the Hough transform to find straight lines within an image. The image comes from the rockland.png file. Please download this file and place it in the examples/data sub-directory under your IDL directory.

NOTE: If you left-click on the above link, your browser may display the image. To download the image instead, right-click on the above link and choose "Save Target As..." from the pop-up menu.

The image is a saturation composite of a 24-hour period in Rockland, Maine. A saturation composite is normally used to highlight intensities, but the Hough transform is used in this example to extract the power lines, which are straight lines. The Hough transform is applied to the green band of the image. The results of the transform are scaled to only include lines longer than 100 pixels. The scaled results are then backprojected by the Hough transform to produce an image of only the power (straight) lines.

Code Example: 

PRO findingPowerLinesInRocklandME

    ; Determine path to file.
    file = FILEPATH('rockland.png', $
     SUBDIRECTORY = ['examples', 'data'])

    ; Import image from file into IDL.
    image = READ_PNG(file)

    ; Determine size of image.
    imageSize = SIZE(image, /DIMENSIONS)

    ; Display cropped image
    DEVICE, DECOMPOSED = 1
    WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2], $
     TITLE = 'Rockland, Maine'
    TV, image, TRUE = 1

    ; Use layer from green channel as the intensity of the
    ; image.
    intensity = REFORM(image[1, *, *])

    ; Determine size of intensity image.
    intensitySize = SIZE(intensity, /DIMENSIONS)

    ; Mask intensity image to highlight power lines.
    mask = intensity GT 240

    ; Transform mask.
    transform = HOUGH(mask, RHO = rho, THETA = theta)

    ; Scale transform to obtain just the power lines.
    transform = (TEMPORARY(transform) - 100) > 0

    ; Backproject to compare with original image.
    backprojection = HOUGH(transform, /BACKPROJECT, $
     RHO = rho, THETA = theta, $
     NX = intensitySize[0], NY = intensitySize[1])

    
    ; Reverse color table to clarify lines. If you are on
    ; a TrueColor display, set the DECOMPOSED keyword to 0
    ; before using any color table related routines.
    DEVICE, DECOMPOSED = 0
    LOADCT, 0
    TVLCT, red, green, blue, /GET
    TVLCT, 255 - red, 255 - green, 255 - blue

    ; Display results.
    WINDOW, 1, XSIZE = intensitySize[0], $
     YSIZE = intensitySize[1], $
     TITLE = 'Resulting Power Lines'
    TVSCL, backprojection


END

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »