Itest = zeros(9); Itest(1:3, 6:9) = 1; Itest(4:6, 4:7) = 1; Itest(7:9, 1:4) = 1; my1 = [ 0 1 0;1 1 0; 0 0 0]; my2 = [ 0 0 0; 0 1 1; 0 1 0]; my3 = [ 1 1 0; 1 1 0; 0 0 0]; figure('Name', 'Three asymmetric structuring elements'); subplot(1, 3, 1), imshow(my1, 'notruesize'), title('Element 1'); subplot(1, 3, 2), imshow(my2, 'notruesize'), title('Element 2'); subplot(1, 3, 3), imshow(my3, 'notruesize'), title('Element 3'); myst1 = strel(my1); myst2 = strel(my2); myst3 = strel(my3); Itestopen1 = imopen(Itest,myst1); Itestopen2 = imopen(Itest,myst2); Itestopen3 = imopen(Itest,myst3); figure('Name', 'Open using default boundary handling'); subplot(2, 2, 1), imshow(Itest, 'notruesize'), title('Original'); subplot(2, 2, 2), imshow(Itestopen1, 'notruesize'), title('Element 1'); subplot(2, 2, 3), imshow(Itestopen2, 'notruesize'); title('Element 2'); subplot(2, 2, 4), imshow(Itestopen3, 'notruesize'); title('Element 3'); %Padding to get the traditional open Itestpad1 = padarray(Itest, [3, 3], 0, 'both'); Itestpad2 = padarray(uint8(255*double(Itest)), [3, 3], 128, 'both'); Itestpad1open = imopen(Itestpad1, myst1); Itestpad2open = imopen(Itestpad2, myst1); figure('Name', 'Open with padding'); subplot(2,2,1), imshow(Itestpad1), title('Original binary with 0 pad'); subplot(2,2,2), imshow(Itestpad2), title('Original uint8 with 128 pad'); subplot(2,2,3), imshow(Itestpad1open), title('Opened with 0 pad'); subplot(2,2,4), imshow(Itestpad2open), title('Opened with 128 pad'); Itestpad1ou = Itestpad1open(4:12, 4:12); Itestpad1erode = imerode(Itestpad1,myst1); Itestpad1eu = Itestpad1erode(4:12, 4:12); figure('Name', 'Open - comparison of boundary'); subplot(2,2,1), imshow(Itest), title('Original '); subplot(2,2,2), imshow(Itestpad1ou), title('Opened with 0 pad'); subplot(2,2,3), imshow(Itestpad1eu), title('Erode with 0 pad'); subplot(2,2,4), imshow(Itestopen1), title('Opened using same (default) option'); my4 = ones(3); myst4 = strel(my4); Itestpad4open = imopen(Itestpad1, myst4); Itestpad4ou = Itestpad4open(4:12, 4:12); my5 = ones(5); myst5 = strel(my5); Itestpad5open = imopen(Itestpad1, myst5); Itestpad5ou = Itestpad5open(4:12, 4:12); figure('Name', 'Open comparison of different structuring elements (0 pad)'); subplot(2,2,1), imshow(Itest), title('Original '); subplot(2,2,2), imshow(Itestpad1ou), title('Opened with 0 pad'); subplot(2,2,3), imshow(Itestpad4ou), title('Opened with 3x3'); subplot(2,2,4), imshow(Itestpad5ou), title('Opened using 5x5'); enam = imread('enamel.tif'); enamcomp = imcomplement(enam); enamcpad = padarray(enamcomp, [3, 3], 0, 'both'); enamcomp4open = imopen(enamcpad, myst4); enamcomp5open = imopen(enamcpad, myst5); enamcomp4ou = enamcomp4open(4:(end-3), 4:(end-3)); enamcomp5ou = enamcomp5open(4:(end-3), 4:(end-3)); my6 = ones(7); myst6 = strel(my6); enamcomp6open = imopen(enamcpad, myst6); enamcomp6ou = enamcomp6open(6:(end-5), 6:(end-5)); figure('Name', 'Enamel'); subplot(2, 2, 1), imshow(enam), title('Original'); subplot(2, 2, 2), imshow(enamcomp), title('Complemented'); figure('Name', 'Enamel - Opened'); subplot(2, 2, 1), imshow(enamcomp), title('Complemented'); subplot(2, 2, 2), imshow(enamcomp4ou), title('Opened with 3x3'); subplot(2, 2, 3), imshow(enamcomp5ou), title('Opened with 5x5'); subplot(2, 2, 4), imshow(enamcomp6ou), title('Opened with 7x7');