% Mathematical morphology demos % % Du Huynh % March 2007 % binary image A = zeros(8,7); A(2:3,4:5) = 1; A(4:6,3:5) = 1; % structure element B = strel('arbitrary', [0 1 0; 0 1 1; 0 0 0]); disp('Input binary image ='); disp(A); disp('Structure element ='); disp(B); disp('imdilate(A,B) ='); imdilate(A,B) disp(' '); disp('See lecture note for the definition of Bhat.'); disp('Bhat = '); Bhat = strel('arbitrary', [0 0 0; 1 1 0; 0 1 0]); disp('Erosion of image A by element B is the complement of A complement'); disp('being dilated by Bhat.'); Acomplement = ~A disp('~imdilate(Acomplement, Bhat) ='); disp(~imdilate(Acomplement, Bhat)); disp('imerode(A,B) ='); disp(imerode(A,B)); % the open and close operations are imopen and imclose.