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. Run the example procedure by entering forwardhoughandradon at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT forwardhoughandradon.pro.
- Import the first image from the
abnorm.datfile: - Define the display size and offset parameters to resize and position the images when displaying them:
- Initialize the display:
- Create a window and display the image:
- With the HOUGH function, transform the image into the Hough domain:
- Create another window and display the Hough transform with axes provided by the PLOT procedure:
- With the RADON function, transform the image into the Radon domain with axes provided by the PLOT procedure:
- Create another window and display the Radon transform:
imageSize = [64, 64] file = FILEPATH('abnorm.dat', $ SUBDIRECTORY = ['examples', 'data']) image = READ_BINARY(file, DATA_DIMS = imageSize)
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.
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.5The following figure shows the resulting Hough transform.
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.5The following figure shows the resulting Radon transform.
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. Run the example procedure by entering backprojecthoughandradon at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT backprojecthoughandradon.pro.
- Import in the first image from the
abnorm.datfile: - Define the display size and offset parameters to resize and position the images when displaying them:
- Initialize the display:
- With the HOUGH function, transform the image into the Hough domain:
- Create another window and display the Hough transform with axes provided by the PLOT procedure:
- With the RADON function, transform the image into the Radon domain with axes provided by the PLOT procedure:
- Create another window and display the Radon transform:
- Backproject the Hough and Radon transforms:
- Create another window and display the original image with the Hough and Radon backprojections:
imageSize = [64, 64] file = FILEPATH('abnorm.dat', $ SUBDIRECTORY = ['examples', 'data']) image = READ_BINARY(file, DATA_DIMS = imageSize)
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
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.5The following figure shows the Hough and Radon transforms.
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])
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]), 2The 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.
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. Run the example procedure by entering findinglineswithhough at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT findinglineswithhough.pro.
- Import the image from the
rockland.pngfile: - Determine the size of the image:
- Initialize a TrueColor display:
- Create a window and display the original image:
- Use the image from green channel to provide an outline of shapes:
- Determine the size of the intensity image derived from the green channel:
- Threshold the intensity image to highlight the power lines:
- Initialize the remaining displays:
- Create another window and display the masked image:
- Transform the mask with the HOUGH function:
- Define the size and offset parameters for the transform displays:
- Reverse the color table to clarify the lines:
- Create another window and display the Hough transform with axes provided by the PLOT procedure:
- Scale the transform to obtain just the power lines, retaining only those lines longer than 85 pixels:
- Create another window and display the scaled Hough transform with axes provided by the PLOT procedure:
- Backproject to compare with the original image:
- Create another window and display the resulting backprojection:
WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2], $ TITLE = 'Rockland, Maine' TV, image, TRUE = 1The following figure shows the original image.
mask = intensity GT 240Note
The intensity image values range from 0 to 255. The threshold was derived by iteratively viewing the intensity image at several different values.
WINDOW, 1, XSIZE = intensitySize[0], $ YSIZE = intensitySize[1], $ TITLE = 'Mask to Locate Power Lines' TVSCL, maskThe following figure shows the mask of the original image.
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
transform = (TEMPORARY(transform) - 85) > 0The value of 85 comes from an estimate of the length of the power lines within the original and intensity images.
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.BACKGROUNDThe 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.
backprojection = HOUGH(transform, /BACKPROJECT, $ RHO = rho, THETA = theta, $ NX = intensitySize[0], NY = intensitySize[1])
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. Run the example procedure by entering contrastingcellswithradon at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT contrastingcellswithradon.pro.
- Import in the image from the
endocell.jpgfile: - Determine the image's size, but divide it by 4 to reduce the image:
- Resize the image to a quarter of its original length and width:
- Initialize the display:
- Create a window and display the original image:
- Filter the original image to clarify the edges of the cells and display it:
file = FILEPATH('endocell.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, endocellImage
WINDOW, 0, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original (left) and Filtered (right)' TV, endocellImage, 0
The following figure shows the results of the edge detection filter.
- Transform the filtered image:
- Define the size and offset parameters for the transform displays:
- Create another window and display the Radon transform with axes provided by the PLOT procedure:
- Scale the transform to include only the density values above the mean of the transform:
- Create another window and display the scaled Radon transform with axes provided by the PLOT procedure:
- Backproject the scaled transform:
- Create another window and display the backprojection:
- Use the backprojection as a mask to provide a color density contrast of the original image:
- Display the resulting contrast image:
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
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.5The 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.
backprojection = RADON(scaledTransform, /BACKPROJECT, $ RHO = rho, THETA=theta, NX = imageSize[0], $ NY = imageSize[1])
WINDOW, 3, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Backproject (left) and Final Result (right)' TVSCL, backprojection, 0











