I'm working on a matlab image processing project which basically extracts components and connections from an image of hand-drawn circuit diagram.
After preproccessing and obtaining skeleton image, I tried to use Hough transform to detect the lines so that i can identify corners and connection paths.
Here is the code:
[H,T,R] = hough(im);
peaks = houghpeaks(H,50,'Threshold',ceil(0.3*max(H(:))));
lines = houghlines(im, T,R,peaks, 'Fillgap', 20, 'MinLength', 20);
figure; imshow(im);
title('Lines detected');
hold on;
for l=1:length(lines)
xy = [lines(l).point1; lines(l).point2];
if ((lines(l).theta == 0)||(lines(l).theta >= 355 && lines(l).theta < 5)) || (lines(l).theta < 95 && lines(l).theta > 85) % detect only approx. horizontal and vertical lines
plot(xy(:,1),xy(:,2), 'LineWidth', 2);
end
end
This is the input and output that i got when executing:
I need to detect all the line segments, that are almost horizontal or vertical, having minimum length, with some irregularities due to hand drawn nature.
In given screenshot, the output image shows only few detected lines, and some of lines are partially detected. It should actually detect all the wires used to connect components
How can i tune Hough transform functions or use any other methods to achieve this requirement ?