mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-04 20:09:02 +08:00
Reformat code to comply with PEP8
This commit is contained in:
@@ -84,14 +84,14 @@ def skeletonize(image):
|
||||
# look up table - there is one entry for each of the 2^8=256 possible
|
||||
# combinations of 8 binary neighbours. 1's, 2's and 3's are candidates
|
||||
# for removal at each iteration of the algorithm.
|
||||
lut = [ 0,0,0,1,0,0,1,3,0,0,3,1,1,0,1,3,0,0,0,0,0,0,0,0,2,0,2,0,3,0,3,3,
|
||||
0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,3,0,2,2,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
2,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,3,0,2,0,
|
||||
0,0,3,1,0,0,1,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
|
||||
3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
2,3,1,3,0,0,1,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
2,3,0,1,0,0,0,1,0,0,0,0,0,0,0,0,3,3,0,1,0,0,0,0,2,2,0,0,2,0,0,0]
|
||||
lut = [0,0,0,1,0,0,1,3,0,0,3,1,1,0,1,3,0,0,0,0,0,0,0,0,2,0,2,0,3,0,3,3,
|
||||
0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,3,0,2,2,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
2,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,3,0,2,0,
|
||||
0,0,3,1,0,0,1,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
|
||||
3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
2,3,1,3,0,0,1,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
2,3,0,1,0,0,0,1,0,0,0,0,0,0,0,0,3,3,0,1,0,0,0,0,2,2,0,0,2,0,0,0]
|
||||
|
||||
# convert to unsigned int (this should work for boolean values)
|
||||
skeleton = np.array(image).astype(np.uint8)
|
||||
@@ -106,13 +106,13 @@ def skeletonize(image):
|
||||
|
||||
# create the mask that will assign a unique value based on the
|
||||
# arrangement of neighbouring pixels
|
||||
mask = np.array([[1, 2, 4],
|
||||
mask = np.array([[ 1, 2, 4],
|
||||
[128, 0, 8],
|
||||
[64, 32, 16]], np.uint8)
|
||||
[ 64, 32, 16]], np.uint8)
|
||||
|
||||
pixelRemoved = True
|
||||
while pixelRemoved:
|
||||
pixelRemoved = False
|
||||
pixel_removed = True
|
||||
while pixel_removed:
|
||||
pixel_removed = False
|
||||
|
||||
# assign each pixel a unique value based on its foreground neighbours
|
||||
neighbours = ndimage.correlate(skeleton, mask, mode='constant')
|
||||
@@ -126,11 +126,11 @@ def skeletonize(image):
|
||||
# pass 1 - remove the 1's and 3's
|
||||
code_mask = (codes == 1)
|
||||
if np.any(code_mask):
|
||||
pixelRemoved = True
|
||||
pixel_removed = True
|
||||
skeleton[code_mask] = 0
|
||||
code_mask = (codes == 3)
|
||||
if np.any(code_mask):
|
||||
pixelRemoved = True
|
||||
pixel_removed = True
|
||||
skeleton[code_mask] = 0
|
||||
|
||||
# pass 2 - remove the 2's and 3's
|
||||
@@ -139,11 +139,11 @@ def skeletonize(image):
|
||||
codes = np.take(lut, neighbours)
|
||||
code_mask = (codes == 2)
|
||||
if np.any(code_mask):
|
||||
pixelRemoved = True
|
||||
pixel_removed = True
|
||||
skeleton[code_mask] = 0
|
||||
code_mask = (codes == 3)
|
||||
if np.any(code_mask):
|
||||
pixelRemoved = True
|
||||
pixel_removed = True
|
||||
skeleton[code_mask] = 0
|
||||
|
||||
return skeleton.astype(bool)
|
||||
|
||||
Reference in New Issue
Block a user