% opening
clear
BW = zeros(8,8);
BW(4:6,4:7) = 1;
BW(3,5:6)=1;BW(2,5)=1;
BW(7,5:6)=1;BW(8,6)=1;
BW(3:5,3)=1;BW(4,2)=1;BW(3,5:6);BW % input image
SE = strel([1 1 0;0 1 0;1,0,0]); % structuring element
BW3 = imerode(BW,SE);
BW4 = imdilate(BW3,SE) % output
BW5 = imopen(BW,SE)  % output

