击中击不中变换Matlab实现

matlab击中击不中函数为bwhitmiss,调用形式为:

Ihm = bwhitmiss(I, S1, S2);
% I为输入图像
% S1、S2为结构元素

The syntax bwhitmiss(BW1,SE1,SE2) is equivalent to imerode(BW1,SE1) & imerode(~BW1,SE2)


更为直观的实现方式代码:

clear all;
I = zeros(120,180);
I(11:80,16:75) = 1;
I(56:105,86:135) = 1;
I(26:55,141:170) = 1;
figure,imshow(I);

se = zeros(58,58);
se(5:54,5:54) = 1;
figure,imshow(se);

%击中击不中变换
Ie1 = imerode(I,se);
figure,imshow(Ie1);

Ic = 1 - I;
figure,imshow(Ic);
S2 = 1 - se;
figure;imshow(S2);
Ie2 = imerode(Ic,S2);
figure,imshow(Ie2);

Ihm = Ie1 & Ie2;
figure,imshow(Ihm);


你可能感兴趣的:(MATLAB)