MATLAB Answers

Help with line detection in image!

64 views (last 30 days)
Aliyu Abdu
Aliyu Abdu on 2 May 2012
I want to get rid of all lines(excluding the text) from my image: Below is the code I'm using;
I = imread('1b.bmp');
%rotI = imrotate(I,33,'crop');
%fig1 = imshow(rotI);
%se = strel('line',12,90);
%BW = imdilate(BW,se);
BW = bwmorph(I,'thicken');
%BW = edge(BW,'canny');
%BW1 = imrotate(BW,90,'crop');
figure, imshow(BW);
[H,theta,rho] = hough(BW,'Theta',-90:0.5:89.5);
figure, imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,...
xlabel('\theta (degrees)'), ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H,8,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',5);
figure, imshow(BW), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
% Plot beginnings and ends of lines
% plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
% highlight the longest line segment
The code can detect most of the lines but not all. I need help with the code so that it can detect all the lines, and remove them leaving only the text. You can also suggest a better way of doing it if you think there is. Please help!


Sign in to comment.

Answers (0)

Translated by