میشه بهم کمک کنید که چطوری میشه خط های یک تصویر را آشکار کرد..من مثال مطلب رو هم خوندم اما کمکی بهم نکرده
ممنون.
ممنون.
[pre]
I = imread('tehran congestion.jpg'
;
BW = rgb2gray(I);
F = edge(BW,'horizontal','sobel'
;
figure, imshow(F);
[H,theta,rho] = hough(BW);
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,3,'threshold',ceil(0.3*max( H(
)));
x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','bla ck'
;
lines = houghlines(BW,theta,rho,P,'FillGap',5,&# 039;MinLength',7);
figure, imshow(I), 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[/pre]
I = imread('tehran congestion.jpg'

BW = rgb2gray(I);
F = edge(BW,'horizontal','sobel'

figure, imshow(F);
[H,theta,rho] = hough(BW);
figure, imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,. ..
'InitialMagnification','fit'

xlabel('\theta (degrees)'


axis on, axis normal, hold on;
colormap(hot)
P = houghpeaks(H,3,'threshold',ceil(0.3*max( H(

x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','bla ck'

lines = houghlines(BW,theta,rho,P,'FillGap',5,&# 039;MinLength',7);
figure, imshow(I), 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
دیدگاه