script2
clear
close all
bw = imread('btext.png');
imshow(imresize(bw,4,'nearest'));
se = strel('disk',2)
bw2 = imerode(bw,se);
imshow(imresize(bw2,4,'nearest'));
se =
Flat STREL object containing 13 neighbors.
Neighborhood:
0 0 1 0 0
0 1 1 1 0
1 1 1 1 1
0 1 1 1 0
0 0 1 0 0
sz = size(bw2);
for n=1:sz(1)
for m=1:sz(2)
if bw2(n,m) fprintf('1');
else fprintf(' ');
end
end
fprintf('\n');
end
1111111111
11111 11111111111111111111111 111111 111
11111 11111 111111 11111 11
111111 1111 1111 11111 111
1111111 111 1111 11111 111
11111111 111 111 11111 1
1111 1111 111 111 11111
111 1111 111 111 1111
111 111 111 111 1111
11 1111 111 111 111
111 111 111 111 111
11 1111 111 111 1111
111 111 1111 111 1111
11 1111 11111 1111 111
111 111 11111111111111111111111 111
11 1111 11111 1111 111
111 1111 1111 111 111
11 1111 111 1111 1111
1111 11111 111 1111 111
11111 1111111 111 111 111
11111111111111111111111 111 111 111
1111 11111 111 111 1111
1111 1111 111 111 1111
111 1111 111 111 11111
111 1111 111 1111 11111 11
111 1111 111 1111 11111 11
111 1111 1111 11111 11111 11
111 1111 11111 111111 11111 11
111 1111 11111111111111111111111 111111 111
1111111111
bw3 = imdilate(bw,se);
showbin(bw3);
1111111111
11111111111 111111111111111111111111111 11111111111111111
1111111111111 1111111111111111111111111111111 111111111111111111111
111111111111111 111111111111111111111111111111111 111111111111111111111111
1111111111111 111111111111111111111111111111111 1111111111111111111111111111
1111111111111 111111111111111111111111111111111 11111111111111111111111111111111
1111111111111 1111111111111111111111111111111111 1111111111111111111111111111111111
11111111111111 1111111111111111111111111111111111 111111111111111111111111111111111111
111111111111111 11111111111111111111111111111111111 11111111111111111111111111111111111
1111111111111111 11111111111111111111111111111111111 111111111111111 111111111111
11111111111111111 11111111111 11111111111 1111111111111 111111111
111111111111111111 11111111111 11111111111 111111111111 1111111
1111111111111111111 11111111111 11111111111 111111111111 11111
11111111111111111111 11111111111 11111111111 11111111111 111
111111111111111111111 11111111111111111111111111111111111 11111111111 1
1111111111111111111111 1111111111111111111111111111111111 111111111111
11111111111 11111111111 1111111111111111111111111111111111 111111111111
1111111111 111111111111 111111111111111111111111111111111 11111111111
11111111111 11111111111 11111111111111111111111111111111 11111111111
1111111111 111111111111 111111111111111111111111111111111 11111111111
111111111111111111111111111 1111111111111111111111111111111111 11111111111
1111111111111111111111111111 11111111111111111111111111111111111 111111111111
11111111111111111111111111111 111111111111111111111111111111111111 11111111111
111111111111111111111111111111 11111111111 111111111111 11111111111 1
1111111111111111111111111111111 11111111111 11111111111 11111111111 111
11111111111111111111111111111111 11111111111 11111111111 111111111111 11111
111111111111111111111111111111111 11111111111 11111111111 111111111111 111111
1111111111111111111111111111111111 11111111111 111111111111 1111111111111 111111111
11111111111111111111111111111111111 111111111111111111111111111111111111 111111111111111 1111111111111
11111111111 111111111111 11111111111111111111111111111111111 11111111111111111111111111111111111
11111111111 111111111111 11111111111111111111111111111111111 11111111111111111111111111111111111
11111111111 111111111111 1111111111111111111111111111111111 111111111111111111111111111111111
11111111111 111111111111 111111111111111111111111111111111 11111111111111111111111111111 1
1111111111111 1111111111111 111111111111111111111111111111111 11111111111111111111111111
111111111111111 111111111111111 111111111111111111111111111111111 111111111111111111111111
1111111111111 1111111111111 1111111111111111111111111111111 111111111111111111111
11111111111 11111111111 111111111111111111111111111 11111111111111111
1111111111
subplot(1,3,1);
imshow(imresize(bw,4,'nearest'));
title('original');
subplot(1,3,2);
imshow(imresize(bw2,4,'nearest'));
title('eroded');
subplot(1,3,3);
imshow(imresize(bw3,4,'nearest'));
title('dilated');
imwrite(bw2,'eroded.png');
imwrite(bw3,'dilated.png');