系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 网络编程 > 其它综合 > 详细页面

一文详解matlab实现形态学图像处理

时间:2023-03-09来源:系统城装机大师作者:佚名

文章和代码以及样例图片等相关资源,已经归档至【Github仓库:digital-image-processing-matlab】

  • 膨胀的简单应用、使用 strel 函数、腐蚀的说明
  • 函数imopen 和imclose 的应用、使用IPT函数bwhitmiss
  • 灰度图像形态学开运算和闭运算
  • 灰度图像形态学使用重构删除复杂图像的背景

内容

膨胀的简单应用

1
2
3
4
5
A=imread('D:\pic\DIP3E_CH04\Fig0419(a)(text_gaps_of_1_and_2_pixels).tif');
figure, imshow(A)
B=[0 1 0;1 1 1;0 1 0];
A2=imdilate(A,B);
figure,imshow(A2)

使用 strel 函数分解结构元素的说明

1
2
3
4
5
6
7
se=strel('diamond',5)
decomp=getsequence(se);
whos
decomp(1)
decomp(2)
decomp(3)
decomp(4)

腐蚀的说明

1
2
3
4
5
6
7
8
9
10
A=imread('D:\pic\DIP3E_CH09\Fig0905(a)(wirebond-mask).tif');
figure, imshow(A)%原图像
se=strel('disk',10)
A2=imerode(A,se)
figure, imshow(A2)%半径为10 的圆盘腐蚀后的图像
se=strel('disk',5)
A3=imerode(A,se)
figure, imshow(A3)%半径为5 的圆盘腐蚀后的图像
A4=imerode(A,strel('disk',20))
figure, imshow(A4)%半径为20 的圆盘腐蚀后的图像

函数imopen 和imclose 的应用

1
2
3
4
5
6
7
8
9
f=imread('D:\pic\DIP3E_CH09\Fig0905(a)(wirebond-mask).tif');
figure, imshow(f)%原图像
se=strel('square',20);
fo=imopen(f,se);
figure, imshow(fo)%开运算后的图像
fc=imclose(f,se);
figure, imshow(fc)%闭运算后的图像
foc=imclose(fo,se);
figure, imshow(foc)%图像A2 经闭运算后的图像

使用 IPT 函数bwhitmiss

1
2
3
4
5
6
f=imread('D:\pic\DIP3E_CH09\FigP0918(left).tif')
figure,imshow(f)
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);
figure,imshow(g)

灰度图像形态学开运算和闭运算

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
%%%%%%%%%使用开运算和闭运算做形态学平滑%%%%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0941(a)(wood_dowels).tif');
figure, imshow(f)%原图像
se=strel('disk',5);
fo=imopen(f,se);
figure, imshow(fo)%开运算后的图像
foc=imclose(fo,se);
figure, imshow(foc)%图像A2 经闭运算后的图像
fasf=f;
for k=2:5
    se=strel('disk',k);
    fasf=imclose(imopen(fasf,se),se);
end
figure,imshow(fasf) %%%%%% 交替顺序滤波后的图像
%%%%%%%%%%使用顶帽变换%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
figure, imshow(f)%原图像
se=strel('disk',10);
fo=imopen(f,se);
figure, imshow(fo)%经开运算处理后的图像
f2=imsubtract(f,fo);
figure, imshow(f2)
f2=imtophat(f,se);
figure, imshow(f2)
se=strel('disk',3);
g=imsubtract(imadd(f,imtophat(f,se)),imbothat(f,se));%低帽、顶帽
figure, imshow(g)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%颗粒分析%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
sumpixels=zeros(1,36);
for k=0:35
    se=strel('disk',k);
    fo=imopen(f,se);
    sumpixels(k+1)=sum(fo(:));
end
figure,plot(0:35,sumpixels);
xlabel('k');
ylabel('surface area')
figure, plot(-diff(sumpixels))
xlabel('k');
ylabel('surface area reduction')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

灰度图像形态学使用重构删除复杂图像的背景

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
%灰度图像形态学使用重构删除复杂图像的背景
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0944(a)(calculator).tif');
figure, imshow(f)%原图像
f_obr=imreconstruct(imerode(f,ones(1,71)),f);
figure, imshow(f_obr)
f_o=imopen(f,ones(1,71));%for comparison
figure, imshow(f_o)
f_thr=imsubtract(f,f_obr);
figure, imshow(f_thr)
f_th=imsubtract(f,f_o);%or imtophat(f,ones(1,71))
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));
figure, imshow(g_obrd)
f2=imreconstruct(min(g_obrd,f_thr),f_thr);
figure, imshow(f2)
分享到:

相关信息

  • 网页资源阻塞浏览器加载的原理示例解析

    测试前环境准备 图片会造成阻塞吗? CSS 加载阻塞 CSS 会阻塞后面 JS 的执行吗? JS 加载阻塞 defer 和 async 动态脚本会造成阻塞吗? DOMContentLoaded 和 onload DOMContentLoaded 遇到脚本 DOMContentLoaded 遇到样式...

    2023-03-09

  • C++的输入和输出流详解

    输入和输出流从键盘输入数据,输出到显示器屏幕。这种输入输出称为标准的输入输出,简称标准I/O。从磁盘文件输入数据,数据输出到磁盘文件简称文件I/O。对内存中指定的空间进行输...

    2022-03-01

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载