From 74bde135c9b3b48b369317ef8471aae5afacd7c1 Mon Sep 17 00:00:00 2001 From: Neil Yager Date: Thu, 13 Oct 2011 08:29:32 +0100 Subject: [PATCH] Added skeleonize example --- doc/examples/plot_skeleton.py | 27 +++++++++++++++++++++++++ scikits/image/morphology/skeletonize.py | 9 ++------- 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 doc/examples/plot_skeleton.py diff --git a/doc/examples/plot_skeleton.py b/doc/examples/plot_skeleton.py new file mode 100644 index 00000000..2c6fed27 --- /dev/null +++ b/doc/examples/plot_skeleton.py @@ -0,0 +1,27 @@ +from scikits.image.morphology import skeletonize +import numpy as np +import matplotlib.pyplot as plt + +image = np.zeros((400, 400)) +image[10:-10, 10:100] = 1 +image[-100:-10, 10:-10] = 1 +image[10:-10, -100:-10] = 1 + +skeleton = skeletonize.skeletonize(image) + +plt.figure(figsize=(8,5)) + +plt.subplot(121) +plt.imshow(image, cmap=plt.cm.gray) +plt.axis('off') +plt.title('original', fontsize=20) + +plt.subplot(122) +plt.imshow(skeleton, cmap=plt.cm.gray) +plt.axis('off') +plt.title('skeleton', fontsize=20) + +plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.98, + bottom=0.02, left=0.02, right=0.98) + +plt.show() \ No newline at end of file diff --git a/scikits/image/morphology/skeletonize.py b/scikits/image/morphology/skeletonize.py index 696eafdd..325448a0 100644 --- a/scikits/image/morphology/skeletonize.py +++ b/scikits/image/morphology/skeletonize.py @@ -52,7 +52,7 @@ def skeletonize(image): while pixelRemoved: pixelRemoved = False; - # pass 1 + # pass 1 - remove the 1's and 3's neighbours = correlate(skeleton, mask, mode='constant') neighbours[skeleton == 0] = 0 codes = np.take(lut, neighbours) @@ -63,7 +63,7 @@ def skeletonize(image): pixelRemoved = True skeleton[codes == 3] = 0 - # pass 2 + # pass 2 - remove the 2's and 3's neighbours = correlate(skeleton, mask, mode='constant') neighbours[skeleton == 0] = 0 codes = np.take(lut, neighbours) @@ -74,9 +74,4 @@ def skeletonize(image): pixelRemoved = True skeleton[codes == 3] = 0 - - return skeleton - - - \ No newline at end of file