Skip to content

Commit 1e7a9bb

Browse files
committed
Add 08
1 parent f6ca772 commit 1e7a9bb

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
- [Matlab实现形态学图像处理](#matlab实现形态学图像处理)
2+
- [目的](#目的)
3+
- [内容](#内容)
4+
- [膨胀的简单应用](#膨胀的简单应用)
5+
- [函数imopen 和imclose 的应用](#函数imopen-和imclose-的应用)
6+
- [灰度图像形态学开运算和闭运算](#灰度图像形态学开运算和闭运算)
7+
- [灰度图像形态学使用重构删除复杂图像的背景](#灰度图像形态学使用重构删除复杂图像的背景)
8+
9+
10+
# Matlab实现形态学图像处理
11+
12+
## 目的
13+
14+
1. 膨胀的简单应用、使用 strel 函数、腐蚀的说明
15+
16+
2. 函数imopen 和imclose 的应用、使用IPT函数bwhitmiss
17+
18+
3. 灰度图像形态学开运算和闭运算
19+
20+
4. 灰度图像形态学使用重构删除复杂图像的背景
21+
22+
## 内容
23+
24+
### 膨胀的简单应用
25+
26+
```matlab
27+
A=imread('D:\pic\DIP3E_CH04\Fig0419(a)(text_gaps_of_1_and_2_pixels).tif');
28+
figure, imshow(A)
29+
B=[0 1 0;1 1 1;0 1 0];
30+
A2=imdilate(A,B);
31+
figure,imshow(A2)
32+
```
33+
34+
使用 strel 函数分解结构元素的说明
35+
36+
```matlab
37+
se=strel('diamond',5)
38+
decomp=getsequence(se);
39+
whos
40+
decomp(1)
41+
decomp(2)
42+
decomp(3)
43+
decomp(4)
44+
```
45+
46+
腐蚀的说明
47+
48+
```matlab
49+
A=imread('D:\pic\DIP3E_CH09\Fig0905(a)(wirebond-mask).tif');
50+
figure, imshow(A)%原图像
51+
se=strel('disk',10)
52+
A2=imerode(A,se)
53+
figure, imshow(A2)%半径为10 的圆盘腐蚀后的图像
54+
se=strel('disk',5)
55+
A3=imerode(A,se)
56+
figure, imshow(A3)%半径为5 的圆盘腐蚀后的图像
57+
A4=imerode(A,strel('disk',20))
58+
figure, imshow(A4)%半径为20 的圆盘腐蚀后的图像
59+
```
60+
61+
### 函数imopen 和imclose 的应用
62+
63+
```matlab
64+
f=imread('D:\pic\DIP3E_CH09\Fig0905(a)(wirebond-mask).tif');
65+
figure, imshow(f)%原图像
66+
se=strel('square',20);
67+
fo=imopen(f,se);
68+
figure, imshow(fo)%开运算后的图像
69+
fc=imclose(f,se);
70+
figure, imshow(fc)%闭运算后的图像
71+
foc=imclose(fo,se);
72+
figure, imshow(foc)%图像A2 经闭运算后的图像
73+
```
74+
75+
使用 IPT 函数bwhitmiss
76+
77+
```matlab
78+
f=imread('D:\pic\DIP3E_CH09\FigP0918(left).tif')
79+
figure,imshow(f)
80+
B1=strel([0 0 0;0 1 1;0 1 0]);
81+
B2=strel([1 1 1;1 0 0;1 0 0]);
82+
g=bwhitmiss(f,B1,B2);
83+
figure,imshow(g)
84+
```
85+
86+
### 灰度图像形态学开运算和闭运算
87+
88+
```matlab
89+
%%%%%%%%%使用开运算和闭运算做形态学平滑%%%%%%%%%%%%%%%%%
90+
clear all
91+
clc
92+
f=imread('D:\pic\DIP3E_CH09\Fig0941(a)(wood_dowels).tif');
93+
figure, imshow(f)%原图像
94+
se=strel('disk',5);
95+
fo=imopen(f,se);
96+
figure, imshow(fo)%开运算后的图像
97+
foc=imclose(fo,se);
98+
figure, imshow(foc)%图像A2 经闭运算后的图像
99+
100+
fasf=f;
101+
for k=2:5
102+
se=strel('disk',k);
103+
fasf=imclose(imopen(fasf,se),se);
104+
end
105+
figure,imshow(fasf) %%%%%% 交替顺序滤波后的图像
106+
107+
%%%%%%%%%%使用顶帽变换%%%%%%%%%%%%%%
108+
clear all
109+
clc
110+
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
111+
figure, imshow(f)%原图像
112+
se=strel('disk',10);
113+
fo=imopen(f,se);
114+
figure, imshow(fo)%经开运算处理后的图像
115+
116+
f2=imsubtract(f,fo);
117+
figure, imshow(f2)
118+
119+
f2=imtophat(f,se);
120+
figure, imshow(f2)
121+
122+
se=strel('disk',3);
123+
g=imsubtract(imadd(f,imtophat(f,se)),imbothat(f,se));%低帽、顶帽
124+
figure, imshow(g)
125+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126+
127+
128+
%%%%%%%%%%%颗粒分析%%%%%%%%%%%%%%
129+
clear all
130+
clc
131+
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
132+
sumpixels=zeros(1,36);
133+
for k=0:35
134+
se=strel('disk',k);
135+
fo=imopen(f,se);
136+
sumpixels(k+1)=sum(fo(:));
137+
end
138+
figure,plot(0:35,sumpixels);
139+
xlabel('k');
140+
ylabel('surface area')
141+
142+
figure, plot(-diff(sumpixels))
143+
xlabel('k');
144+
ylabel('surface area reduction')
145+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146+
```
147+
148+
### 灰度图像形态学使用重构删除复杂图像的背景
149+
150+
```matlab
151+
%灰度图像形态学使用重构删除复杂图像的背景
152+
clear all
153+
clc
154+
f=imread('D:\pic\DIP3E_CH09\Fig0944(a)(calculator).tif');
155+
figure, imshow(f)%原图像
156+
f_obr=imreconstruct(imerode(f,ones(1,71)),f);
157+
figure, imshow(f_obr)
158+
159+
f_o=imopen(f,ones(1,71));%for comparison
160+
figure, imshow(f_o)
161+
162+
f_thr=imsubtract(f,f_obr);
163+
figure, imshow(f_thr)
164+
f_th=imsubtract(f,f_o);%or imtophat(f,ones(1,71))
165+
figure, imshow(f_th)
166+
167+
g_obr=imreconstruct(imerode(f_thr,ones(1,11)),f_thr);
168+
figure, imshow(g_obr)
169+
170+
g_obrd=imdilate(g_obr,ones(1,21));
171+
figure, imshow(g_obrd)
172+
173+
f2=imreconstruct(min(g_obrd,f_thr),f_thr);
174+
figure, imshow(f2)
175+
```
176+
177+
参考文献:
178+
179+
[1] [Rafael C. Gonzalez, Richard E. Woods, and Steven L. Eddins. 2003. Digital Image Processing Using MATLAB. Prentice-Hall, Inc., USA.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_Using_Matlab.pdf)
180+
181+
[2] [阮秋琦. 数字图像处理(MATLAB版)[M]. 北京:电子工业出版社, 2014.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_(MATLAB_version).pdf)
182+
183+
[3] [冈萨雷斯. 数字图像处理(第三版)[M]. 北京:电子工业出版社, 2011.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_(Third_Edition).pdf)
184+
185+
[返回首页](https://github.com/timerring/digital-image-processing-matlab)

0 commit comments

Comments
 (0)