Previous Image Processing in IDL: Transforming Between Domains Next

Transforming to and from the Hough and Radon Domains

The Hough transform is used to transform from the spatial domain to the Hough domain and back again. The image information within the Hough domain shows the pixels of the original (spatial) image as sinusoidal curves. If the points of the original image form a straight line, their related sinusoidal curves in the Hough domain will intersect. Many intersections produce a peak. Masks can be easily applied to the image within the Hough domain to determine if and where straight lines occur.

The Radon transform is used to transform from the spatial domain to the Radon domain and back again. The image information within the Radon domain shows a line through the original image as a point. Specific features (geometries) in the original image produce peaks or collections of points. Masks can be easily applied to the image within the Radon domain to determine if and where these specific features occur.

Unlike transformations to and from the frequency and time-frequency domains, the Hough and Radon transforms do lose some data during the transformation process. These transformations are usually applied to the original image as a mask instead of producing an image from the results of the transform itself. See the HOUGH and RADON descriptions in the IDL Reference Guide for more information on Hough and Radon transform theory.

The following sections introduce the concepts needed to work with images and these transforms:

The Hough transformation process is used to find straight lines within an image. See Finding Straight Lines with the Hough Transform for an example. The Radon transformation process is used to enhance contrast within an image. See Color Density Contrasting with the Radon Transform for an example.

Transforming to the Hough and Radon Domains (Projecting)

When an image is transformed from the spatial domain to either the Hough or Radon domain, the transformation process is referred to as a Hough or Radon projection. The projection process can be performed with either IDL's HOUGH function or IDL's RADON function, depending on which transform you want to use.

The following example shows how to use IDL's HOUGH and RADON functions to compute and display the Hough and Radon projections. This example uses the first image within the abnorm.dat file, which is in the examples/data directory. Complete the following steps for a detailed description of the process.


Example Code
See forwardhoughandradon.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example.

  1. Import the first image from the abnorm.dat file:
  2. imageSize = [64, 64]  
    file = FILEPATH('abnorm.dat', $  
       SUBDIRECTORY = ['examples', 'data'])  
    image = READ_BINARY(file, DATA_DIMS = imageSize)  
    

     

  3. Define the display size and offset parameters to resize and position the images when displaying them:
  4. displaySize = 2*imageSize  
    offset = displaySize/3  
    

     

  5. Initialize the display:
  6. DEVICE, DECOMPOSED = 0  
    LOADCT, 0  
    

     

  7. Create a window and display the image:
  8. WINDOW, 0, XSIZE = displaySize[0], $  
       YSIZE = displaySize[1], TITLE = 'Original Image'  
    TVSCL, CONGRID(image, displaySize[0], $  
       displaySize[1])  
    

     

    The following figure shows the original image.

     

    Figure 7-22: Original Gated Blood Pool Image

    Figure 7-22: Original Gated Blood Pool Image

     

  9. With the HOUGH function, transform the image into the Hough domain:
  10. houghTransform = HOUGH(image, RHO = houghRadii, $  
       THETA = houghAngles, /GRAY)  
    

     

  11. Create another window and display the Hough transform with axes provided by the PLOT procedure:
  12. WINDOW, 1, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Hough Transform'  
    TVSCL, CONGRID(houghTransform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, houghAngles, houghRadii, /XSTYLE, /YSTYLE, $  
       TITLE = 'Hough Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5  
    

     

    The following figure shows the resulting Hough transform.

     

    Figure 7-23: Hough Transform of the Gated Blood Pool Image

    Figure 7-23: Hough Transform of the Gated Blood Pool Image

     

  13. With the RADON function, transform the image into the Radon domain with axes provided by the PLOT procedure:
  14. radonTransform = RADON(image, RHO = radonRadii, $  
       THETA = radonAngles, /GRAY)  
    

     

  15. Create another window and display the Radon transform:
  16. WINDOW, 2, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Radon Transform'  
    TVSCL, CONGRID(radonTransform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, radonAngles, radonRadii, /XSTYLE, /YSTYLE, $  
       TITLE = 'Radon Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5  
    

     

    The following figure shows the resulting Radon transform.

     

    Figure 7-24: Radon Transform of the Gated Blood Pool Image

    Figure 7-24: Radon Transform of the Gated Blood Pool Image

Transforming from the Hough and Radon Domains (Backprojecting)

After manipulating an image within either the Hough or Radon domain, you may need to transform the image from that domain back to the spatial domain. This transformation process is referred to as a Hough or Radon backprojection. The backprojection process can be performed with either IDL's HOUGH function or IDL's RADON function, depending on which domain your image is in. You can perform the backprojection process with these functions by setting the BACKPROJECT keyword.

The following example shows how to use IDL's HOUGH and RADON functions to compute the backprojection from these domains. This example uses the first image within the abnorm.dat file, which is in the examples/data directory. Although the image is not manipulated while it is in the Hough or Radon domain, information is lost when using these transforms. Complete the following steps for a detailed description of the process.


Example Code
See backprojecthoughandradon.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example.

  1. Import in the first image from the abnorm.dat file:
  2. imageSize = [64, 64]  
    file = FILEPATH('abnorm.dat', $  
       SUBDIRECTORY = ['examples', 'data'])  
    image = READ_BINARY(file, DATA_DIMS = imageSize)  
    

     

  3. Define the display size and offset parameters to resize and position the images when displaying them:
  4. displaySize = 2*imageSize  
    offset = displaySize/3  
    

     

  5. Initialize the display:
  6. DEVICE, DECOMPOSED = 0  
    LOADCT, 0  
    

     

  7. With the HOUGH function, transform the image into the Hough domain:
  8. houghTransform = HOUGH(image, RHO = houghRadii, $  
       THETA = houghAngles, /GRAY)  
    

     

  9. Create another window and display the Hough transform with axes provided by the PLOT procedure:
  10. WINDOW, 1, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Hough Transform'  
    TVSCL, CONGRID(houghTransform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, houghAngles, houghRadii, /XSTYLE, /YSTYLE, $  
       TITLE = 'Hough Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5  
    

     

  11. With the RADON function, transform the image into the Radon domain with axes provided by the PLOT procedure:
  12. radonTransform = RADON(image, RHO = radonRadii, $  
       THETA = radonAngles, /GRAY)  
    

     

  13. Create another window and display the Radon transform:
  14. WINDOW, 2, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Radon Transform'  
    TVSCL, CONGRID(radonTransform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, radonAngles, radonRadii, /XSTYLE, /YSTYLE, $  
       TITLE = 'Radon Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5  
    

     

    The following figure shows the Hough and Radon transforms.

     

    Figure 7-25: Hough (left) and Radon (right) Transforms of Image

    Figure 7-25: Hough (left) and Radon (right) Transforms of Image

     

  15. Backproject the Hough and Radon transforms:
  16. backprojectHough = HOUGH(houghTransform, /BACKPROJECT, $  
       RHO = houghRadii, THETA = houghAngles, $  
       NX = imageSize[0], NY = imageSize[1])  
    backprojectRadon = RADON(radonTransform, /BACKPROJECT, $  
       RHO = radonRadii, THETA = radonAngles, $  
       NX = imageSize[0], NY = imageSize[1])  
    

     

  17. Create another window and display the original image with the Hough and Radon backprojections:
  18. WINDOW, 2, XSIZE = (3*displaySize[0]), $  
       YSIZE = displaySize[1], $  
       TITLE = 'Hough and Radon Backprojections'  
    TVSCL, CONGRID(image, displaySize[0], $  
       displaySize[1]), 0  
    TVSCL, CONGRID(backprojectHough, displaySize[0], $  
       displaySize[1]), 1  
    TVSCL, CONGRID(backprojectRadon, displaySize[0], $  
       displaySize[1]), 2  
    

     

    The following figure shows the original image and its Hough and Radon transforms. These resulting images shows information is blurred when using the Hough and Radon transformations.

     

    Figure 7-26: Original Gated Blood Pool Image (left), Hough Backprojection (center), and Radon Backprojection (right)

    Figure 7-26: Original Gated Blood Pool Image (left), Hough Backprojection (center), and Radon Backprojection (right)

Finding Straight Lines with the Hough Transform

This example uses the Hough transform to find straight lines within an image. The image comes from the rockland.png file found in the examples/data directory. 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 85 pixels. The scaled results are then backprojected by the Hough transform to produce an image of only the straight power lines. Complete the following steps for a detailed description of the process.


Example Code
See findinglineswithhough.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example.

  1. Import the image from the rockland.png file:
  2. file = FILEPATH('rockland.png', $  
       SUBDIRECTORY = ['examples', 'data'])  
    image = READ_PNG(file)  
    

     

  3. Determine the size of the image:
  4. imageSize = SIZE(image, /DIMENSIONS)  
    

     

  5. Initialize a TrueColor display:
  6. DEVICE, DECOMPOSED = 1  
    

     

  7. Create a window and display the original image:
  8. WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2], $  
       TITLE = 'Rockland, Maine'  
    TV, image, TRUE = 1  
    

     

    The following figure shows the original image.

     

    Figure 7-27: Image of Rockland, Maine

    Figure 7-27: Image of Rockland, Maine

     

  9. Use the image from green channel to provide an outline of shapes:
  10. intensity = REFORM(image[1, *, *])  
    

     

  11. Determine the size of the intensity image derived from the green channel:
  12. intensitySize = SIZE(intensity, /DIMENSIONS)  
    

     

  13. Threshold the intensity image to highlight the power lines:
  14. mask = intensity GT 240  
    

     

     


    Note
    The intensity image values range from 0 to 255. The threshold was derived by iteratively viewing the intensity image at several different values.

     

  15. Initialize the remaining displays:
  16. DEVICE, DECOMPOSED = 0  
    LOADCT, 0  
    

     

  17. Create another window and display the masked image:
  18. WINDOW, 1, XSIZE = intensitySize[0], $  
       YSIZE = intensitySize[1], $  
       TITLE = 'Mask to Locate Power Lines'  
    TVSCL, mask  
    

     

    The following figure shows the mask of the original image.

     

    Figure 7-28: Mask of Rockland Image

    Figure 7-28: Mask of Rockland Image

     

  19. Transform the mask with the HOUGH function:
  20. transform = HOUGH(mask, RHO = rho, THETA = theta)  
    

     

  21. Define the size and offset parameters for the transform displays:
  22. displaySize = [256, 256]  
    offset = displaySize/3  
    

     

  23. Reverse the color table to clarify the lines:
  24. TVLCT, red, green, blue, /GET  
    TVLCT, 255 - red, 255 - green, 255 - blue  
    

     

  25. Create another window and display the Hough transform with axes provided by the PLOT procedure:
  26. WINDOW, 2, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Hough Transform'  
    TVSCL, CONGRID(transform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, theta, rho, /XSTYLE, /YSTYLE, $  
       TITLE = 'Hough Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5, $  
       COLOR = !P.BACKGROUND  
    

     

  27. Scale the transform to obtain just the power lines, retaining only those lines longer than 85 pixels:
  28. transform = (TEMPORARY(transform) - 85) > 0  
    

     

    The value of 85 comes from an estimate of the length of the power lines within the original and intensity images.

     

  29. Create another window and display the scaled Hough transform with axes provided by the PLOT procedure:
  30. WINDOW, 2, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Scaled Hough Transform'  
    TVSCL, CONGRID(transform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, theta, rho, /XSTYLE, /YSTYLE, $  
       TITLE = 'Scaled Hough Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5, $  
       COLOR = !P.BACKGROUND  
    

     

    The top image in the following figure shows the Hough transform of the intensity image. This transform is masked to only include straight lines of more than 85 pixels. The bottom image in the following figure shows the results of this mask. Only the far left and right intersections are retained.

     

    Figure 7-29: The Hough Transform (top) and the Scaled Transform (bottom) of the Masked Intensity Image

    Figure 7-29: The Hough Transform (top) and the Scaled Transform (bottom) of the Masked Intensity Image

     

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

     

  33. Create another window and display the resulting backprojection:
  34. WINDOW, 4, XSIZE = intensitySize[0], $  
       YSIZE = intensitySize[1], $  
       TITLE = 'Resulting Power Lines'  
    TVSCL, backprojection  
    

     

    The following figure shows the resulting backprojection, which contains only the power lines.

     

    Figure 7-30: The Resulting Backprojection of the Scaled Hough Transform

    Figure 7-30: The Resulting Backprojection of the Scaled Hough Transform

Color Density Contrasting with the Radon Transform

This example uses the Radon transform to provide more contrast within an image based on its color density. The image comes from the endocell.jpg file found in the examples/data directory. The image is a photomicrograph of cultured endothelial cells. The edges (outlines) within the image are defined by the Roberts filter. The Radon transform is then applied to the filtered image. The transform is scaled to only include the values above the mean of the transform. The scaled results are backprojected by the Radon transform. The resulting backprojection is used as a mask on the original image. The final resulting image shows more color contrast along the edges of the cell nuclei within the image.


Example Code
See contrastingcellswithradon.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example.

  1. Import in the image from the endocell.jpg file:
  2. file = FILEPATH('endocell.jpg', $  
       SUBDIRECTORY = ['examples', 'data'])   
    READ_JPEG, file, endocellImage  
    

     

  3. Determine the image's size, but divide it by 4 to reduce the image:
  4. imageSize = SIZE(endocellImage, /DIMENSIONS)/4  
    

     

  5. Resize the image to a quarter of its original length and width:
  6. endocellImage = CONGRID(endocellImage, $  
       imageSize[0], imageSize[1])  
    

     

  7. Initialize the display:
  8. DEVICE, DECOMPOSED = 0  
    LOADCT, 0  
    

     

  9. Create a window and display the original image:
  10. WINDOW, 0, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $  
       TITLE = 'Original (left) and Filtered (right)'  
    TV, endocellImage, 0  
    

     

  11. Filter the original image to clarify the edges of the cells and display it:
  12. image = ROBERTS(endocellImage)  
    TVSCL, image, 1  
    

The following figure shows the results of the edge detection filter.

 

Figure 7-31: Original Image (left) and the Resulting Edge-Filtered Image (right)

Figure 7-31: Original Image (left) and the Resulting Edge-Filtered Image (right)

  1. Transform the filtered image:
  2. transform = RADON(image, RHO = rho, THETA = theta)  
    

     

  3. Define the size and offset parameters for the transform displays:
  4. displaySize = [256, 256]  
    offset = displaySize/3  
    

     

  5. Create another window and display the Radon transform with axes provided by the PLOT procedure:
  6. WINDOW, 1, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Radon Transform'  
    TVSCL, CONGRID(transform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, theta, rho, /XSTYLE, /YSTYLE, $  
       TITLE = 'Radon Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5  
    

     

  7. Scale the transform to include only the density values above the mean of the transform:
  8. scaledTransform = transform > MEAN(transform)  
    

     

  9. Create another window and display the scaled Radon transform with axes provided by the PLOT procedure:
  10. WINDOW, 2, XSIZE = displaySize[0] + 1.5*offset[0], $  
       YSIZE = displaySize[1] + 1.5*offset[1], $  
       TITLE = 'Scaled Radon Transform'  
    TVSCL, CONGRID(scaledTransform, displaySize[0], $  
       displaySize[1]), offset[0], offset[1]  
    PLOT, theta, rho, /XSTYLE, /YSTYLE, $  
       TITLE = 'Scaled Radon Transform', XTITLE = 'Theta', $  
       YTITLE = 'Rho', /NODATA, /NOERASE, /DEVICE, $  
       POSITION = [offset[0], offset[1], $  
       displaySize[0] + offset[0], $  
       displaySize[1] + offset[1]], CHARSIZE = 1.5  
    

     

    The following figure shows the original Radon transform of the edge-filtered image and the resulting scaled transform. The high intensity values within the diamond shape of the center of the transform represent high color density within the filtered and original image. The transform is scaled to highlight this segment of intersecting lines.

     

     

    Figure 7-32: Radon Transform (top) and Scaled Transform (bottom)
    of the Edge-Filtered Image

    Figure 7-32: Radon Transform (top) and Scaled Transform (bottom)
    of the Edge-Filtered Image

     

  11. Backproject the scaled transform:
  12. backprojection = RADON(scaledTransform, /BACKPROJECT, $  
       RHO = rho, THETA=theta, NX = imageSize[0], $  
       NY = imageSize[1])  
    

     

  13. Create another window and display the backprojection:
  14. WINDOW, 3, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $  
       TITLE = 'Backproject (left) and Final Result (right)'  
    TVSCL, backprojection, 0  
    

     

  15. Use the backprojection as a mask to provide a color density contrast of the original image:
  16. constrastingImage = endocellImage*backprojection  
    

     

  17. Display the resulting contrast image:
  18. TVSCL,constrastingImage, 1  
    

     

    The following figure shows the Radon backprojection and a combined image of the original and the backprojection. The cell nuclei now have more contrast than the rest of the image.

     

    Figure 7-33: The Backprojection of the Radon Transform and the Resulting Contrast Image

    Figure 7-33: The Backprojection of the Radon Transform and the Resulting Contrast Image
      
    

  IDL Online Help (June 16, 2005)