>> 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)
一个简单应用 :
函数 imdilate 执行膨胀运算 ,基本调用语法为:
A2 = imdilate(A, B);
A2 和 A 都是二值图像 ,B是指定结构元素的由0和1组成的矩阵。
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分解结构元素的说明
>> 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
(不知道为什么没直接显示,但是结果是没问题的)
腐蚀由函数 imerode 执行
>> 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)
应用:
>> 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)
另一应用:
>> 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)
可基于膨胀,腐蚀和查找表操作的组合实现许多有用的操作,语法为:
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)