フィルターのクリア

Hough transform doesn't detect some lines

14 ビュー (過去 30 日間)
Jack Smith
Jack Smith 2015 年 3 月 21 日
コメント済み: Image Analyst 2020 年 10 月 17 日
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 件のコメント
Jack Smith
Jack Smith 2015 年 3 月 21 日
Tried increasing threshold value. Still unable to detect all the lines * (see my comment to first answer below) * . Someone please help.
Jack Smith
Jack Smith 2015 年 3 月 21 日
Also please suggest how to find total number of separate line segments detected.

サインインしてコメントする。

回答 (4 件)

Image Analyst
Image Analyst 2015 年 3 月 21 日
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 件のコメント
Jack Smith
Jack Smith 2015 年 3 月 21 日
編集済み: Jack Smith 2015 年 3 月 22 日
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.

サインインしてコメントする。


Image Analyst
Image Analyst 2015 年 3 月 22 日
Jack:
Try the attached code. Change your folder and image name before you run it.
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 9 月 20 日
Jack Smith commented
I want to understand why Hough transform is unable to detect all the lines.
Image Analyst
Image Analyst 2015 年 9 月 20 日
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.

サインインしてコメントする。


sonia carole
sonia carole 2016 年 2 月 2 日
I = imread('SAM_0160.jpg');
I=imresize(I,[640 480]);
figure,imshow(I);
rotI =imrotate(I,33,'crop');
bw_I =rgb2gray(rotI);
BW = edge(bw_I,'canny');
figure; imshow(BW);
[H,T,R] = hough(BW);
imshow(H,[],'XData',T,'YData',R,...
'InitialMagnification','fit');
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));
plot(x,y,'s','color','white');
% 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(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
%plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
%plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% 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;
end
end
% highlight the longest line segment %plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','blue');
  3 件のコメント
Spencer Glubay
Spencer Glubay 2020 年 10 月 17 日
I think your min length is too high or you are don't have enough number of peaks. Both of these will reduce how many lines are displayed in the end.
Image Analyst
Image Analyst 2020 年 10 月 17 日
Try taking the radon transform and see if you can see peaks at the expected angles.

サインインしてコメントする。


Satadru Mukherjee
Satadru Mukherjee 2020 年 7 月 21 日
Simple Code , no need Hough--
clc
clear all
close all
warning off
x=imbinarize(rgb2gray(imread('Capture.JPG')));
imshow(x);
impixelinfo;
[r c]=size(x);
l=zeros(r,c);
se=strel('line',60,0);
imshow(x);
l=l+imopen(x,se);
imshow(l);
se=strel('line',60,90);
imshow(x);
l=l+imopen(x,se);
imshow(l);

Community Treasure Hunt

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

Start Hunting!

Translated by