Hough transform doesn't detect some lines

31 visualizaciones (últimos 30 días)
Jack Smith
Jack Smith el 21 de Mzo. de 2015
Comentada: Image Analyst el 17 de Oct. de 2020
Hi, I tried using Hough transform to detect all the straight lines in an image below
so that only logic gates remain in the image. But Hough transform detect only some lines as shown in figure an the detected lines are colored in green.
Can someone please tell what could the reason. What is the best, robust function in matlab to detect lines in image that can work on any type of image. If Hough transform is the best available one, what can be done to increase its robustness to detect all straight lines that can be used in any type of image.The code used is below one where BW_ConnComp is a binary inverted image. The "lines" calculated is drawn in green.
img = edge(BW_ConnComp,'prewitt');
figure, imshow(img), hold on
[H,T,R] = hough(img);
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(BW,T,R,P,'FillGap',5);
  2 comentarios
Jack Smith
Jack Smith el 21 de Mzo. de 2015
Also please suggest how to find total number of separate line segments detected.

Iniciar sesión para comentar.

Respuestas (4)

Image Analyst
Image Analyst el 21 de Mzo. de 2015
Try changing the threshold, or not calling edge() at all. Not sure why you called edge in the fist place. I mean it already has edges and calling edge just turns a single edge into a double edge - just look at your image and you'll see.
  1 comentario
Jack Smith
Jack Smith el 21 de Mzo. de 2015
Editada: Jack Smith el 22 de Mzo. de 2015
Thank you for the answer. I tried increasing the threshold value from 0.3*max(H(:)) to 0.5*max(H(:)) and removed edge() function. I only got an improvement of detection of just one more line (line B/W NOT & AND gates) , and still three lines are yet to be detected (as in above fig four lines are undetected). If I try to increase threshold value further, then the lines already detected are also getting undetected.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 22 de Mzo. de 2015
Try the attached code. Change your folder and image name before you run it.
  2 comentarios
Image Analyst
Image Analyst el 20 de Sept. de 2015
Jack, they were probably not selected due to the threshold level. Attach a specific example (code plus image) in a new question if you want more help.

Iniciar sesión para comentar.

sonia carole
sonia carole el 2 de Feb. de 2016
I = imread('SAM_0160.jpg');
I=imresize(I,[640 480]);
rotI =imrotate(I,33,'crop');
bw_I =rgb2gray(rotI);
BW = edge(bw_I,'canny');
figure; imshow(BW);
[H,T,R] = hough(BW);
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H,5,'threshold',ceil(0.6*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
% Find lines and plot them
lines = houghlines(BW,T,R,P,'FillGap',30,'MinLength',15);
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
% Plot beginnings and ends of lines
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
% highlight the longest line segment %plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','blue');
  3 comentarios
Image Analyst
Image Analyst el 17 de Oct. de 2020
Try taking the radon transform and see if you can see peaks at the expected angles.

Iniciar sesión para comentar.

Satadru Mukherjee
Satadru Mukherjee el 21 de Jul. de 2020
Simple Code , no need Hough--
clear all
close all
warning off
[r c]=size(x);

Community Treasure Hunt

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

Start Hunting!

Translated by