# Excluding Hough transform artifacts at 45 and -45 degrees

11 views (last 30 days)
KAE on 16 Sep 2019
Commented: Jordan Kennedy on 22 Oct 2020
I am following steps in this example to find lines in my image, which contains a lot of nearly-horizontal lines. The Hough transform identifies several lines correctly, but there are additional incorrect lines at exactly 45 and -45 degrees, making an 'X' in my square image. I think these are a mathematical artifact (see Samuel Liew's answer here), and I would like to exclude them. The following works, but is there a better way? Or if you understand this artifact, could you please explain it?
angleList = -90:89; % All the permissable angles (note 90 can't be included)
angleList(angleList==45 | angleList==-45) = []; % Remove problematic -45, 45 degree angles
[H,T,R] = hough(BW, 'Theta', angleList);
Jordan Kennedy on 22 Oct 2020
In my dataset, I have true 45 degree artificats that are falsly amplified by the 45 degree angle artificat. So I did not want to remove 45 entirely. I still needed to maintain the true signal. With Michael Knetzger's explaination for the error I decided to use a 1D median filter on the H output of the Hough Transform. This is apart of the Signal Processing Toolbox. This seemed to work well for me.
tempangle = medfilt1(H,10,'truncate');

Michael Knetzger on 5 Dec 2019
Dear KAE,
since I had also issues with the 45 degree artifacts and your idea helped me I'll give you an explanation on how I see those artifacts.
You're following the examples in the documentation, so at one point you have am edge detected image. Although the lines have a preferred direction, the pixels are discret. So every step of your line from a horrizontal (or vertical) direction in order to form an inclined line is your 45 degree artifact.
So what you detect is this:
Therefore your soultion is sufficient, if you insist on having the full angular range, you need to alter your edge detection.
KAE on 9 Dec 2019
Very nice detective work, thanks. This must be a common occurance for line detection in raster images.

### Categories

Find more on Object Analysis in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by