emag = imread('edge3.tif'); Thigh = 160 Tlow = 20 Ehigh = emag>Thigh; Elow = (Tlow<=emag) & (emag<=Thigh); figure(1) subplot(2,2,1); imshow(emag, []) subplot(2,2,2); imshow(Ehigh, []) s=1; while s>0 d = bwdist(Ehigh, 'chessboard'); %d = bwdist(Ehigh, 'cityblock'); d(Elow==0)=0; X = (d==1); Ehigh = Ehigh | X; subplot(2,2,3); imshow(X, []) subplot(2,2,4); imshow(Ehigh, []) s=sum(X(:)) pause(0.1) end pause(5) subplot(2,2,3);imshow(Tlow<=emag, []) if 0 L = bwlabel(Ehigh,8); stats = regionprops(L, 'Area'); idx = find([stats.Area] >= 30); E = ismember(L,idx); figure(2); imshow(E, []) figure(3); imshow(L, []) end