forked from ckxajd/final
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2160504134-自动化65-张文轩.txt
65 lines (65 loc) · 1.63 KB
/
2160504134-自动化65-张文轩.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
clc
clear
pt = 'D:\z-数字图像作业\第七次作业\';
dis=dir(pt);
names={dis.name};
t=0;
for i=1:length(names)
try
image=imread(names{i});
nm=names{i}
[c,r]=find(nm=='.')
name=nm(1:r-1)
catch
continue
end
try
image=rgb2gray(image);
catch
end
figure
level = graythresh(image);
subplot(2,2,1)
imshow(image)
title(name)
BW = imbinarize(image,level);
BW_sobel = edge(BW,'sobel');
subplot(2,2,2)
imshow(BW_sobel)
title("sobel 边缘检测")
BW_Roberts = edge(image,'Roberts');
subplot(2,2,3)
imshow(BW_Roberts)
title("Roberts 边缘检测")
BW_canny = edge(image,'Canny');
subplot(2,2,4)
imshow(BW_canny);
title("canny 边缘检测")
figure
for num=1:3
switch num
case 1
p= BW_sobel;
case 2
p=BW_Roberts;
case 3
p=BW_canny;
end
[H, theta, rho]= hough(p,'Theta',-90:0.5:89);
peak=houghpeaks(H , 20,'Threshold',0.3*max(H(:)));
lines=houghlines(p ,theta,rho,peak);
subplot(2,2,1)
imshow(image)
title(name)
subplot(2,2,num+1)
imshow(p ,[])
title('Hough Transform Detect Result')
hold on
for k=1:length(lines)
xy=[lines(k).point1;lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color',[1 0 0]);
end
pictitle={"sobel边缘检测后hough直线检测","Roberts边缘检测后hough直线检测", "canny边缘检测后hough直线检测"};
title(pictitle{num})
end
end