From 2de03d018ab49b0d0fc1f7d4cf7aaf616f805c8a Mon Sep 17 00:00:00 2001 From: Christian Sachs Date: Tue, 30 Jun 2015 15:07:04 +0200 Subject: [PATCH] reordered code according to PEP8, modified docstring --- skimage/morphology/_skeletonize_cy.pyx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/skimage/morphology/_skeletonize_cy.pyx b/skimage/morphology/_skeletonize_cy.pyx index 4272f294..0ff419b3 100644 --- a/skimage/morphology/_skeletonize_cy.pyx +++ b/skimage/morphology/_skeletonize_cy.pyx @@ -7,15 +7,15 @@ import numpy as np cimport numpy as cnp def _fast_skeletonize(image): - """Optimized parts of the Zhang-Suen skeletonization. + """Optimized parts of the Zhang-Suen [1] skeletonization. Iteratively, pixels meeting removal criteria are removed, till only the skeleton remains (that is, no further removable pixel was found). + Performs a hard-coded correlation to assign every neighborhood of 8 a unique number, which in turn is used in conjunction with a look up table to select the appropriate thinning criteria. - Parameters ---------- image : numpy.ndarray @@ -27,6 +27,12 @@ def _fast_skeletonize(image): skeleton : ndarray A matrix containing the thinned image. + References + ---------- + .. [1] A fast parallel algorithm for thinning digital patterns, + T. Y. ZHANG and C. Y. SUEN, Communications of the ACM, + March 1984, Volume 27, Number 3 + """ # look up table - there is one entry for each of the 2^8=256 possible @@ -91,9 +97,9 @@ def _fast_skeletonize(image): 64*skeleton[row + 1, col - 1] + 128*skeleton[row, col - 1]] # if the condition is met, the pixel is removed (unset) - if (first_pass and neighbors == 1) or\ - ((not first_pass) and neighbors == 2) or\ - neighbors == 3: + if ((neighbors == 1 and first_pass) or + (neighbors == 2 and not first_pass) or + (neighbors == 3)): cleaned_skeleton[row, col] = 0 pixel_removed = True