
306 A Computational Introduction to Digital Image Processing, Second Edition
MATLAB/Octave
function skel = imskel(image,kernel)
% IMSKEL - Calculates the skeleton of IMAGE using kernel KERNEL
%
skel=zeros(size(image));
e=image;
while (any(e(:))),
o=imopen(e,kernel);
skel=skel | (e&~o);
e=imerode(e,kernel);
end
and in Python:
Python
def bwskel(im,ker):
skel = np.zeros
_
like(im)
from skimage.morphology import binary
_
erosion, binary
_
opening
e = (np.copy(im)>0)
*
1
while e.max()>0:
o = binary
_
opening(e,ker)
skel = skel | (e & 1-o)
e = binary
_
erosion(e,ker)
return skel
Exercises
1. For each of the following images A
i
and structuring elements B
j
:
A
1
= A
2
= A
3
=
0 0 0 0 0 0 0 0