Main Content

Detect Lines Using the Radon Transform

This example shows how to use the Radon transform to detect lines in an image. The Radon transform is closely related to a common computer vision operation known as the Hough transform. You can use theradonfunction to implement a form of the Hough transform used to detect straight lines.

Compute the Radon Transform of an Image

Read an image into the workspace. Convert it into a grayscale image.

I = fitsread('solarspectra.fts'); I = rescale(I);

Display the original image.

figure imshow(I) title('Original Image')

Figure contains an axes object. The axes object with title Original Image contains an object of type image.

Compute a binary edge image using theedgefunction. Display the binary image returned by theedgefunction.

BW =边缘(I);图imshow (BW)标题('Edges of Original Image')

Figure contains an axes object. The axes object with title Edges of Original Image contains an object of type image.

Calculate the radon transform of the image, using theradonfunction, and display the transform. The locations of peaks in the transform correspond to the locations of straight lines in the original image.

theta = 0:179; [R,xp] = radon(BW,theta);

Display the result of the radon transform.

图显示亮度图像(θ,xp, R);colormap(热);xlabel('\theta (degrees)'); ylabel('x^{\prime} (pixels from center)'); title('R_{\theta} (x^{\prime})'); colorbar

Figure contains an axes object. The axes object with title R indexOf theta baseline blank ( x toThePowerOf prime baseline ) contains an object of type image.

The strongest peak inRcorresponds to θ = 1 degree andx'= -80 pixels from center.

Interpreting the Peaks of the Radon Transform

To visualize this peak in the original figure, find the center of the image, indicated by the blue cross overlaid on the image below. The red dashed line is the radial line that passes through the center at an angle θ = 1 degree. If you travel along this line -80 pixels from center (towards the left), the radial line perpendicularly intersects the solid red line. This solid red line is the straight line with the strongest signal in the Radon transform.

To interpret the Radon transform further, examine the next four strongest peaks inR.

Two strong peaks inRare found at θ = 1 学位,在offsets of -84 and -87 pixels from center. These peaks correspond to the two red lines to the left of the strongest line, overlaid on the image below.

Two other strong peaks are found near the center ofR. These peaks are located at θ = 91 degrees, with offsets of -8 and -44 pixels from center. The green dashed line in the image below is the radial line passing through the center at an angle of 91 degrees. If you travel along the radial line a distance of -8 and -44 pixels from center, then the radial line perpendicularly intersects the solid green lines. These solid green lines correspond to the strong peaks inR.

The fainter lines in the image relate to the weaker peaks inR.