%fig924.m - Figure 9.24 Gonzales and Woods' book % skeletonization example % (C) 2003 by Yu Hen Hu % created: 12/2/2003 clear all A=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; figure(1),clf,colormap('gray') B=ones(3); x{1}=A; for k =1:3, i=6*(k-1)+1; if k>1, x{i}=double(erode(x{i-6},B)); end eval(['subplot(3,6,' int2str(i) '),']),imagesc(x{i}) x{i+1}=double(imopen(x{i},B)); eval(['subplot(3,6,' int2str(i+1) '),']),imagesc(x{i+1}) x{i+2}=x{i}-x{i+1}; eval(['subplot(3,6,' int2str(i+2) '),']),imagesc(x{i+2}) x{i+3}=zeros(size(A)); for j=1:k, x{i+3}=x{i+3}+x{i+2-6*(j-1)}; end eval(['subplot(3,6,' int2str(i+3) '),']),imagesc(x{i+3}) x{i+4} = x{i+2}; if k>1, x{i+4}=dilate(x{i+2},B,k-1); end eval(['subplot(3,6,' int2str(i+4) '),']),imagesc(x{i+4}) x{i+5}=x{i+4}; if k>1, for j=2:k, x{i+5}=or(x{i+5},x{i+4-6*(j-1)}); end, end eval(['subplot(3,6,' int2str(i+5) '),']),imagesc(x{i+5}) end