PK12

This module implements the 3d parallel 12-subiteration thinning algorithm by Palagy & Kuba via parallel convolution of the data with a base template and lookup table matching.

Reference

Palagyi & Kuba, A Parallel 3D 12-Subiteration Thinning Algorithm, Graphical Models and Image Processing 61, 199-221 (1999)

generate_lookup_table(function=<function match_index>, verbose=True)[source]

Generates lookup table for templates

initialize_lookup_table(function=<function match_index>, filename='PK12.npy')[source]

Initialize the lookup table

match(cube)[source]

Match one of the masks in the algorithm.

Arguments

cube3x3x3 bool array

The local binary image.

Returns

matchbool

True if one of the masks matches

Note

Algorithm as in Palagyi & Kuba (1999)

match_index(index, verbose=True)[source]
match_non_removable(index, verbose=True)[source]
skeletonize(binary, points=None, steps=None, removals=False, radii=False, check_border=True, delete_border=False, return_points=False, verbose=True)[source]

Skeletonize a binary 3d array using PK12 algorithm.

Arguments

binaryarray

Binary image to skeletonize.

pointsarray or None.

Optional list of points in the binary to speed up processing.

stepsint or None

Number of maximal iteration steps (if None maximal reduction).

removalsbool

If True, returns also the steps at which the pixels in the input data where removed.

radiibool

If True, the estimate of the local radius is returned.

check_borderbool

If True, check if the boder is empty. The algorithm reuqires this.

delete_borderbool

If True, delete the border.

verbosebool

If True print progress info.

Returns

skeletonarray

The skeleton of the binary.

pointsarray

The point coordinates of the skeleton nx3

Note

The skeletonization is done in place on the binary. Copy the binary if needed for further processing.

skeletonize_index(binary, points=None, steps=None, removals=False, radii=False, return_points=False, check_border=True, delete_border=False, verbose=True)[source]

Skeletonize a binary 3d array using PK12 algorithm via index coordinates.

Arguments

binaryarray

Binary image to be skeletonized.

stepsint or None

Number of maximal iteration steps. If None, use maximal reduction.

removals :bool

If True, returns the steps in which the pixels in the input data were removed.

radii :bool

If True, the estimate of the local radius is returned.

verbose :bool

If True, print progress info.

Returns

skeletonarray

The skeleton of the binary input.

pointsnxd array

The point coordinates of the skeleton.

base = array([[[ 1, 512, 131072], [ 8, 4096, 1048576], [ 64, 16384, 8388608]], [[ 2, 1024, 262144], [ 16, 0, 2097152], [ 128, 32768, 16777216]], [[ 4, 2048, 524288], [ 32, 8192, 4194304], [ 256, 65536, 33554432]]])

Base kernel to multiply with cube to obtain index of cube

consider = array([False, False, False, ..., True, True, True])

Lookup table mapping cube index to whether it needs to be considered further

delete = array([False, False, False, ..., False, False, False])

Lookup table mapping cube index to its deleteability

filename = 'PK12.npy'

Filename for the look up table mapping a cube configuration to the deleatability of the center pixel

filename_non_removable = 'PK12nr.npy'

Filename for the lookup table mapping a cube configuration to the non-removeability of the center pixel

keep = array([ True, True, True, ..., True, True, True])

Lookup table mapping cube index to its non-deleteability

non_removable = array([ True, True, True, ..., False, False, False])

Lookup table mapping cube index to its non-removeability

rotations = [array([[[ 1, 512, 131072], [ 8, 4096, 1048576], [ 64, 16384, 8388608]], [[ 2, 1024, 262144], [ 16, 0, 2097152], [ 128, 32768, 16777216]], [[ 4, 2048, 524288], [ 32, 8192, 4194304], [ 256, 65536, 33554432]]]), array([[[ 64, 128, 256], [ 8, 16, 32], [ 1, 2, 4]], [[ 16384, 32768, 65536], [ 4096, 0, 8192], [ 512, 1024, 2048]], [[ 8388608, 16777216, 33554432], [ 1048576, 2097152, 4194304], [ 131072, 262144, 524288]]]), array([[[ 131072, 512, 1], [ 262144, 1024, 2], [ 524288, 2048, 4]], [[ 1048576, 4096, 8], [ 2097152, 0, 16], [ 4194304, 8192, 32]], [[ 8388608, 16384, 64], [16777216, 32768, 128], [33554432, 65536, 256]]]), array([[[ 4, 2, 1], [ 32, 16, 8], [ 256, 128, 64]], [[ 2048, 1024, 512], [ 8192, 0, 4096], [ 65536, 32768, 16384]], [[ 524288, 262144, 131072], [ 4194304, 2097152, 1048576], [33554432, 16777216, 8388608]]]), array([[[ 4, 2048, 524288], [ 2, 1024, 262144], [ 1, 512, 131072]], [[ 32, 8192, 4194304], [ 16, 0, 2097152], [ 8, 4096, 1048576]], [[ 256, 65536, 33554432], [ 128, 32768, 16777216], [ 64, 16384, 8388608]]]), array([[[ 8388608, 16384, 64], [ 1048576, 4096, 8], [ 131072, 512, 1]], [[16777216, 32768, 128], [ 2097152, 0, 16], [ 262144, 1024, 2]], [[33554432, 65536, 256], [ 4194304, 8192, 32], [ 524288, 2048, 4]]]), array([[[ 131072, 262144, 524288], [ 1048576, 2097152, 4194304], [ 8388608, 16777216, 33554432]], [[ 512, 1024, 2048], [ 4096, 0, 8192], [ 16384, 32768, 65536]], [[ 1, 2, 4], [ 8, 16, 32], [ 64, 128, 256]]]), array([[[ 256, 65536, 33554432], [ 32, 8192, 4194304], [ 4, 2048, 524288]], [[ 128, 32768, 16777216], [ 16, 0, 2097152], [ 2, 1024, 262144]], [[ 64, 16384, 8388608], [ 8, 4096, 1048576], [ 1, 512, 131072]]]), array([[[33554432, 65536, 256], [16777216, 32768, 128], [ 8388608, 16384, 64]], [[ 4194304, 8192, 32], [ 2097152, 0, 16], [ 1048576, 4096, 8]], [[ 524288, 2048, 4], [ 262144, 1024, 2], [ 131072, 512, 1]]]), array([[[33554432, 16777216, 8388608], [ 4194304, 2097152, 1048576], [ 524288, 262144, 131072]], [[ 65536, 32768, 16384], [ 8192, 0, 4096], [ 2048, 1024, 512]], [[ 256, 128, 64], [ 32, 16, 8], [ 4, 2, 1]]]), array([[[ 64, 16384, 8388608], [ 128, 32768, 16777216], [ 256, 65536, 33554432]], [[ 8, 4096, 1048576], [ 16, 0, 2097152], [ 32, 8192, 4194304]], [[ 1, 512, 131072], [ 2, 1024, 262144], [ 4, 2048, 524288]]]), array([[[ 524288, 2048, 4], [ 4194304, 8192, 32], [33554432, 65536, 256]], [[ 262144, 1024, 2], [ 2097152, 0, 16], [16777216, 32768, 128]], [[ 131072, 512, 1], [ 1048576, 4096, 8], [ 8388608, 16384, 64]]])]

Rotations of the base cube for the sub-iterations