Search code examples
matlabimage-processingcomputer-visionhough-transform

Detecting almost straight lines


How to detect almost straight lines in an image using MATLAB? Hough Transform not able to detect the lines properly, as lines are not exactly smooth. And, is there any way to detect all the rectangles in the image or thick lines (assume same color rectangle as a thick line)?? Here is the image enter image description here


Solution

  • Apply canny edge detector to the image and do a labeling and you'll detect most of the rectangles.

    rgb : the image

    edges = edge(rgb2gray(rgb), 'canny');

    labels = label2rgb(bwlabel(edges, 8));

    figure, imshow(edges)

    figure, imshow(labels)