-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathset2q12.m
More file actions
99 lines (96 loc) · 2.39 KB
/
set2q12.m
File metadata and controls
99 lines (96 loc) · 2.39 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
clc;clear all;close all
img=imread('wirebond.tif');
figure,imshow(img); title('Actual Image');
img=double(img);
%Horizontal
hz_mask=[-1 -1 -1 ; 2 2 2 ; -1 -1 -1];
ws=3;
pd=(ws-1)/2;
start=ws-pd;
f=padarray(img,[pd pd],'replicate');
[r,c]=size(f);
for i=start:r-pd
for j=start:c-pd
window=f(i-pd:i+pd,j-pd:j+pd);
su=0;
for s=1:ws
for t=1:ws
su=su+hz_mask(s,t)*window(s,t);
end
end
img_horiz(i-start+1,j-start+1)=su;
end
end
%img_horiz=conv2(img,hz_mask);
T1=max(img_horiz(:));
img_horiz=(img_horiz>=T1).*img_horiz;
figure,subplot(1,2,1); imshow(uint8(img_horiz)); title('Horizontal lines');
%Vertical
ver_mask=[-1 2 -1 ; -1 2 -1 ; -1 2 -1];
ws=3;
pd=(ws-1)/2;
start=ws-pd;
f=padarray(img,[pd pd],'replicate');
[r,c]=size(f);
for i=start:r-pd
for j=start:c-pd
window=f(i-pd:i+pd,j-pd:j+pd);
su=0;
for s=1:ws
for t=1:ws
su=su+ver_mask(s,t)*window(s,t);
end
end
img_vert(i-start+1,j-start+1)=su;
end
end
%img_vert=conv2(img,ver_mask);
T2=max(img_vert(:));
img_vert=(img_vert>=T2).*img_vert;
subplot(1,2,2); imshow(uint8(img_vert)); title('Vertical lines');
%+45 degree
diag1_mask=[2 -1 -1 ; -1 2 -1 ; -1 -1 2];
ws=3;
pd=(ws-1)/2;
start=ws-pd;
f=padarray(img,[pd pd],'replicate');
[r,c]=size(f);
for i=start:r-pd
for j=start:c-pd
window=f(i-pd:i+pd,j-pd:j+pd);
su=0;
for s=1:ws
for t=1:ws
su=su+diag1_mask(s,t)*window(s,t);
end
end
img_diag1(i-start+1,j-start+1)=su;
end
end
%img_diag1=conv2(img,diag1_mask);
T3=max(img_diag1(:));
img_diag1=(img_diag1>=T3).*img_diag1;
figure,subplot(1,2,1); imshow(uint8(img_diag1)); title('Diagonal lines 45 degree');
%-45 degree
diag2_mask=[2 2 2 -1 -1 ; -1 2 2 2 -1 ; -1 -1 2 2 2;-1 -1 -1 2 2 ];
ws=3;
pd=(ws-1)/2;
start=ws-pd;
f=padarray(img,[pd pd],'replicate');
[r,c]=size(f);
for i=start:r-pd
for j=start:c-pd
window=f(i-pd:i+pd,j-pd:j+pd);
su=0;
for s=1:ws
for t=1:ws
su=su+diag2_mask(s,t)*window(s,t);
end
end
img_diag2(i-start+1,j-start+1)=su;
end
end
%img_diag2=conv2(img,diag2_mask);
T4=max(img_diag2(:));
img_diag2=(img_diag2>=T4).*img_diag2;
subplot(1,2,2); imshow(uint8(img_diag2)); title('Diagonal lines -45 degree');