Line detection problem
21 ビュー (過去 30 日間)
古いコメントを表示
I am trying to identify lines in a image using hough transform. Problem is that my lines have finite thickness and edge detection identifies each line as two closely spaced parallel lines.
Detected lines : http://img219.imageshack.us/i/hough1.jpg/ You can notice that each line has been detected as two parallel lines.
Am I taking the right approach? I need to calculate the total length of all those lines in the original image.
The code:
clear all;
I = rgb2gray(imread('dislocations.jpg'));
BW = edge(I,'sobel');
figure, imshow(BW);
[H,theta,rho] = hough(BW,'RhoResolution',1,'ThetaResolution',1);
figure, imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(hot)
P = houghpeaks(H,50,'threshold',ceil(0.2*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','black');
lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',5);
figure, imshow(I), hold on
max_len = 0;
totlen = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',1,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',1,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
totlen = totlen + len; % total length of lines
end
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!