数字图像处理 形态学图像处理(部分)

彩色图像处理

预备知识

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

这里写图片描述

>> f1 = imread('Fig0903(a)(utk).tif');
>> f2 = imread('Fig0903(b)(gt).tif');
>> g1 = ~f1;
>> g2 = f1|f2;
>> g3 = f1&f2;
>> g4 = f1&~f2;
>> subplot(161) ,imshow(f1)
>> subplot(162) ,imshow(f2)
>> subplot(163) ,imshow(g1)
>> subplot(164) ,imshow(g2)
>> subplot(165) ,imshow(g3)
>> subplot(166) ,imshow(g4)

这里写图片描述

腐蚀和膨胀

膨胀

一个简单应用 :web

函数 imdilate 执行膨胀运算 ,基本调用语法为:bash

A2 = imdilate(A, B);

A2 和 A 都是二值图像 ,B是指定结构元素的由0和1组成的矩阵。 svg

A = imread('Fig0906(a)(broken-text).tif');
>> B = [0 1 0;1 1 1;0 1 0];
>> A2 = imdilate(A,B);
>> imshow(A2);
>> figure,imshow(A);

这里写图片描述

函数strel

这里写图片描述

这里写图片描述

这里写图片描述

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

>> se = strel('diamond',5);
>> se

se = 

strel is a diamond shaped structuring element with properties:

      Neighborhood: [11×11 logical]
    Dimensionality: 2

>> decomp = getsequence(se);
>> whos
  Name        Size            Bytes  Class    Attributes

  decomp      4x1               576  strel              
  se          1x1              2264  strel              

>> decomp(1)

ans = 

strel is a arbitrary shaped structuring element with properties:

      Neighborhood: [3×3 logical]
    Dimensionality: 2

>> decomp(2)

ans = 

strel is a arbitrary shaped structuring element with properties:

      Neighborhood: [3×3 logical]
    Dimensionality: 2

>> decomp(3)

ans = 

strel is a arbitrary shaped structuring element with properties:

      Neighborhood: [5×5 logical]
    Dimensionality: 2

>> decomp(4)

ans = 

strel is a arbitrary shaped structuring element with properties:

      Neighborhood: [3×3 logical]
    Dimensionality: 2

(不知道为何没直接显示,可是结果是没问题的)spa

腐蚀

腐蚀由函数 imerode 执行3d

>> f = imread('Fig0908(a)(wirebond-mask).tif');
>> se = strel('disk',10);
>> f2 = imerode(f,se);
>> subplot(121),imshow(f)
>> subplot(122),imshow(f2)

这里写图片描述

>> se = strel('disk',5);
>> f3 = imerode(f,se);
>> f4 = imerode(f,strel('disk',20));
>> subplot(121),imshow(f3)
>> subplot(122),imshow(f4)

这里写图片描述

膨胀与腐蚀的结合

开运算和闭运算

这里写图片描述

应用:code

>> f = imread('Fig0910(a)(shapes).tif');
>> se = strel('square',20);
>> fo = imopen(f,se);
>> fc = imclose(f,se);
>> foc = imclose(fo, se);
>> subplot(221),imshow(f)
>> subplot(222),imshow(fo)
>> subplot(223),imshow(fc)
>> subplot(224),imshow(foc)

这里写图片描述

另外一应用:xml

>> f = imread('Fig0911(a)(noisy-fingerprint).tif');
>> se = strel('square',3);
>> fo = imopen(f,se);
>> foc = imclose(fo,se);
>> subplot(131),imshow(f);
>> subplot(132),imshow(fo);
>> subplot(133),imshow(foc);

这里写图片描述

击中或击不中变换

这里写图片描述

>> f = imread('Fig0913(a)(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]);
>> g = bwhitmiss(f,B1,B2);
>> subplot(121),imshow(f)
>> subplot(122),imshow(g)

这里写图片描述

函数bwmorph

可基于膨胀,腐蚀和查找表操做的组合实现许多有用的操做,语法为:blog

g = bwmorph(f, operation, n);

这里写图片描述

这里写图片描述

细化操做:图片

>> f = imread('Fig0911(a)(noisy-fingerprint).tif');
>> imshow(f);
>> g1 = bwmorph(f, 'thin',1);
>> g2 = bwmorph(f, 'thin',2);
>> ginf = bwmorph(f,'thin', Inf);
>> subplot(141),imshow(f);
>> subplot(142),imshow(g1);
>> subplot(143),imshow(g2);
>> subplot(144),imshow(ginf);

这里写图片描述

骨骼化:

>> f = imread('Fig0916(a)(bone).tif');
>> fs = bwmorph(f,'skel',Inf);
>> subplot(121),imshow(f)
>> subplot(122),imshow(fs)

这里写图片描述