第九章 形态学图像处理

第九章 形态学图像处理

预备知识

二值图像、集合和逻辑运算符

  • 相交(与)
>> g2 = f & g;
>> subplot(131), imshow(f), title('原图')
>> subplot(132), imshow(g), title('第二张图')
>> subplot(133), imshow(g2), title('相交')

这里写图片描述

  • 合并(或)
>> g = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\gt.tif');
>> g1 = f | g;
>> subplot(131), imshow(f), title('原图')
>> subplot(132), imshow(g), title('第二张图')
>> subplot(133), imshow(g1), title('合并')

这里写图片描述

  • 取反运算(非)
>> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\utk.tif');
>> g = ~f;
>> subplot(121), imshow(f), title('原图')
>> subplot(122), imshow(g), title('取反')

这里写图片描述

  • 差运算
>> g3 = f &~ g;
>> subplot(131), imshow(f), title('原图')
>> subplot(132), imshow(g), title('第二张图')
>> subplot(133), imshow(g3), title('差')

这里写图片描述

膨胀和腐蚀

膨胀

膨胀是在二值图像中“加长”或“变粗”的操作。

  • imdilate函数执行膨胀运算
    基本语法: A2 = imdilate(A, B)
    其中,A和A2都是二值图像,B是指定结构元素的由0和1组成的矩阵。
>> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\broken-text.tif');
>> B = [0 1 0; 1 1 1; 0 1 0];
>> f2 = imdilate(f, B);
>> subplot(121), imshow(f), title('原图')
>> subplot(122), imshow(f2), title('膨胀后的图像')
![这里写图片描述](https://img-blog.csdn.net/20170630121604699?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzgzMTEwNDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
  • 函数strel
    基本语法: se = strel(shape, parameters)
    其中,shape是指定希望形状的字符串,parameters是指定形状信息的一列参数
    这里写图片描述
    这里写图片描述

腐蚀

腐蚀“收缩”或“细化”二值图像中的对象。

  • imerode 函数实现图像的腐蚀。其语法于膨胀函数大体一样
>> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\wirebond-mask.tif');
>> se = strel('disk', 10);
>> A2 = imerode(f, se);
>> se = strel('disk', 5);
>> A3 = imerode(f, se);
>> se = strel('disk', 20);
>> A4 = imerode(f, se);
>> subplot(221), imshow(f), title('原图')
>> subplot(222), imshow(A2), title('R = 10')
>> subplot(223), imshow(A3), title('R = 5')
>> subplot(224), imshow(A4), title('R = 20')

这里写图片描述

膨胀与腐蚀的结合

开运算与闭运算

  • C = imopen(A, B)开运算(先腐蚀后膨胀)
  • C = imclose(A, B)闭运算(先膨胀后腐蚀)
    其中,A是一幅二值图像,B是一个元素值为0和1的矩阵。
>> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\shapes.tif');
>> se = strel('square', 20);
>> fo = imopen(f, se);
>> fc = imclose(f, se);
>> foc = imclose(fo, se);
>> subplot(221), imshow(f), title('原图')
>> subplot(222), imshow(fo), title('开运算')
>> subplot(223), imshow(fc), title('闭运算')
>> subplot(224), imshow(foc), title('混合运算')
![这里写图片描述](https://img-blog.csdn.net/20170630124756484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzgzMTEwNDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
>> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\noisy-fingerprint.tif');
>> se = strel('square', 3);
>> fo = imopen(f, se);
>> foc = imclose(fo, se);
>> subplot(131), imshow(f), title('原图')
>> subplot(132), imshow(fo), title('开运算')
>> subplot(133), imshow(foc), title('再闭运算')
![这里写图片描述](https://img-blog.csdn.net/20170630125341037?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzgzMTEwNDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

击中或不击中变换

  • 函数bwhitmiss
    语法:C = bwhitmiss(A, B1, B2)
    其中,C为输出结果,A为输入图像,B1,B2为结构元素
>> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\small-squares.tif');
>> B1 = strel([0 0 0 ;0 1 1;0 1 0]);
>> B2 = strel([1 1 1 ;1 0 0;1 0 0]);
>> C = bwhitmiss(f, B1, B2);
>> subplot(121), imshow(f), title('原图')
>> subplot(122), imshow(C), title('变换后')
![这里写图片描述](https://img-blog.csdn.net/20170630133729666?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzgzMTEwNDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

使用查找表

  • makelut函数基于一个提供给用户的函数构造一个查找表
  • applylut使用makelut产生的查找表来处理二值图像
  • 自定义函数endpoints

    >> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\bone-skel.tif');
    >> g = endpoints(f);
    >> subplot(121), imshow(f), title('原图')
    >> subplot(122), imshow(g), title('使用查找表')

    这里写图片描述

    函数bwmorph

    bwmorph函数可基于膨胀,腐蚀和查找表操作的组合实现操作。
    基本语法:g = bwmorph(f, operation, n)
    其中,f 是一幅输入的二值图像,operation是一个指定期望操作的字符串,n 是一个用于指定将被重复的操作次数的正整数。
    这里写图片描述

>> f = imread('D:\picture\MATLAB\冈萨雷斯数字图像处理MATLAB版图片\dipum_images_ch09\noisy-fingerprint.tif');
>> se = strel('square', 3);
>> fo = imopen(f, se);
>> foc = imclose(fo, se);
>> g1=bwmorph(foc,'thin',1);
>> g2=bwmorph(foc,'thin',2);
>>  subplot(1,3,1),imshow(f), title('原图')
>> subplot(1,3,1),imshow(foc), title('原图')
>> subplot(1,3,2),imshow(g1), title('细化一次')
>> subplot(1,3,3),imshow(g1), title('细化两次')

这里写图片描述

细化无穷次

>> g2=bwmorph(foc,'thin',Inf);
>> figure, imshow(g2)

这里写图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值