-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathm316.m
207 lines (199 loc) · 4.43 KB
/
m316.m
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
% 简单的使用膨胀和腐蚀
% 例子9.2
% A = imread('Fig0906(a).tif');
% B = [0 1 0;1 1 1;0 1 0]; %结构元矩阵
% D = imdilate(A,B);
% figure,
% subplot(121);
% imshow(A)
% title('A')
% subplot(122);
% imshow(D);
% title('D');
%%
% 例子9.3
% A = imread('Fig0908(a).tif');
% se = strel('disk',10);
% E10 = imerode(A,se);
% figure,subplot(221)
% imshow(A)
% subplot(222);
% imshow(E10);
%
% se2 = strel('disk',5);
% E5 = imerode(A,se);
% subplot(223);
% imshow(E5)
%
% E20 = imerode(A,strel('disk',20));
% subplot(224);
% imshow(E20);
%%
% 例子9.5
% f = imread('Fig0913(a).tif');
% B1 = strel([0 0 0;0 1 1;0 1 0]);
% B2 = strel([1 1 1;1 0 0;1 0 0]);
% g = bwhitmiss(f,B1,B2);
% subplot(121);
% imshow(f)
% subplot(122)
% imshow(g);
%%
% 例子934
% f = imread('Fig0911(c).tif');
% ginf1 = bwmorph(f,'thin',1);
% ginf2 = bwmorph(f,'thin',2);
% ginf = bwmorph(f,'thin',Inf);
% subplot(231)
% imshow(ginf1);title('一次细化');
% subplot(232);
% imshow(ginf2);title('两次细化');
% subplot(233);
% imshow(ginf);title('一直到稳定的细化');
%
% f2 = imread('Fig0916(a).tif');
% fs = bwmorph(f2,'skel',Inf);
% subplot(234);
% imshow(f2);title('原始图片');
% for k =1:5
% fs =fs&~endpoints(fs);
% end
% subplot(235);
% imshow(fs);title('使用bwmorph结果')
% fs2 = bwmorph(fs,'spur',5);
% figure,imshow(fs2);x
%%
% 例子9.7,找到每一个质心,并标记出来
% f = imread('Fig0917(a).tif');
% [L,n] = bwlabel(f);
% imshow(f);
% hold on;
% for k =1:n
% [r,c] = find(L == k);
% rbar = mean(r);
% cbar = mean(c);
% plot(cbar,rbar,'Marker','o','MarkerEdgeColor','k',...
% 'MarkerFaceColor','k','MarkerSize',10);
% plot(cbar,rbar,'Marker','*','MarkerEdgeColor','W');
% end
%%
% 例子 9.8 重建
% f = imread('Fig0922(a).tif');
% fe = imerode(f,ones(51,1));
%
% fo = imopen(f,ones(51,1));
% fobr = imreconstruct(fe,f);
% g = imfill(f,'holes');
% g2 = imclearborder(f,4);
%
% subplot(321)
% imshow(f);title('原图')
% subplot(322)
% imshow(fo);title('竖线开操作');
% subplot(323)
% imshow(fobr);title('竖线重建开操作')
% subplot(324)
% imshow(g);title('填充孔洞');
% subplot(325)
% imshow(g2);title('清除边界');
% figure,imshow(g2)
%%
% 例子9-6灰度级别的膨胀腐蚀
% f = imread('068.bmp');
% se = strel('square',3);
% gd = imdilate(f,se);
% ge = imerode(f,se);
% morph_grah = gd-ge;
% figure,imshow(f)
% figure,imshow(gd)
% figure,imshow(ge)
% figure,imshow(morph_grah)
%%
%例子9-9 开操作和闭操作作形态学平滑
% f = imread('Fig0925(a).tif');
% se = strel('disk',5);
% fo = imopen(f,se);
% foc = imclose(fo,se);
%
% figure,imshow(f)
% fasf =f;
% for k =2:5
% se = strel('disk',k);
% fasf = imclose(imopen(fasf,se),se);
% figure,imshow(fasf);
% end
%%
% 例子9-10,非均匀背景 的补偿
% f = imread('Fig0926(a).tif');
% se = strel('disk',10);
% fo = imopen(f,se);
% figure,imshow(fo);%开操作
% f2 = f-fo;
% f2 = imtophat(f2,se);
% figure,imshow(f2); %阈值处理后的效果
%
% se = strel('disk',3);
% g = f+imtophat(f,se) - imbothat(f,se);
% figure,imshow(g);
%%
% 例子9-11 粒度的测定
% f = imread('Fig0925(a).tif');
% sumpixels = zeros(1,36);
% for k =0:35
% se = strel('disk',k);
% fo = imopen(f,se);
% sumpixels(k+1) = sum(fo(:));
% end
% plot(0:35,sumpixels),xlabel('k'),ylabel('Surface area')
% figure
% plot(-diff(sumpixels));
% xlabel('k');
% ylabel('Surface area reduction')
%
% %%
% se = strel('disk',5);
% f = imclose(f,se);
% sumpixels = zeros(1,36);
% for k =0:35
% se = strel('disk',k);
% fo = imopen(f,se);
% sumpixels(k+1) = sum(fo(:));
% end
% figure
% plot(-diff(sumpixels));
% xlabel('k');
% ylabel('Surface area reduction')
%%
% 重建 9-6-3
% f = imread('Fig0925(a).tif');
% se = strel('disk',4);
% fe = imerode(f,se);
% fobr = imreconstruct(fe,f);
%
% fobrc = imcomplement(fobr);
% fobrce = imerode(fobrc,se);
% fobrcbr = imcomplement(imreconstruct(fobrce,fobrc));
%
% figure,imshow(f);
% figure,imshow(fobr);
% figure,imshow(fobrcbr)
%%
% % 例子9-12 移除复杂的背景
% f = imread('Fig0930(a).tif');
% figure,imshow(f);
%
% f_obr = imreconstruct(imerode(f,ones(1,7)),f);
% f_o = imopen(f,ones(1,71));
% figure,imshow(f_o);
%
% f_thr = f - f_obr;
% f_th = f- f_o;
% figure,imshow(f_th);
%
% g_obr = imreconstruct(imerode(f_thr,ones(1,11)),f_thr);
% figure,imshow(g_obr);
%
% g_obrd = imdilate(g_obr,ones(1,21));
% f2 = imreconstruct(min(g_obrd,f_thr),f_thr);
% figure,imshow(f2);
%%