matlabimage-processingcomputer-visionstraight-line-detection

How to detect straight lines on grayscale images?


I have some grayscale image,one of which is shown following:

original

This image is like a “disk” which contains a lot of noise in the non-black area. I want to detect the line in it. The line is easy to be seen by eyes but quite difficult to be seen by computer. I handed out this line for a better demonstration.

show the line

Now I've tried many methods,such as Hough Line transform, Radon transform and so on. However, it's hard to tell whether I used them in a wrong way or those methods do not apply to this task.

I am a beginner in image processing. Could anyone here provide some ideas? Thanks a lot!


Solution

  • You can try using Gabor filters. Here is a start:

    img = imread('https://i.sstatic.net/sHA7w.png');
    % gray out empty spaces
    img(img == 0) = 123;
    % create gabor filter bank
    wavelength = 6;
    orientation = 5:5:180;
    g = gabor(wavelength,orientation);
    outMag = imgaborfilt(img,g);
    % plot the magnitude at peak orientation
    ii = 23;
    figure
    imagesc(outMag(:,:,ii))
    title(['Magnitude at ',num2str(orientation(ii)),'deg'])
    % create a mask
    mask = outMag(:,:,ii) > 250;
    figure;
    imshow(mask)
    

    You still have to detect in which layer you got high magnitude, and filter the mask to hide the edges and small patches.