prune_branches#

Removes dangling branches from a skeleton.

import numpy as np
import porespy as ps
import scipy.ndimage as spim
import matplotlib.pyplot as plt
from skimage.morphology import skeletonize_3d
ps.visualization.set_mpl_style()
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/openpnm/algorithms/_invasion_percolation.py:358: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  def _find_trapped_pores(inv_seq, indices, indptr, outlets):  # pragma: no cover

im#

The function requires a skeleton such as that produced by skimage.mophology.skeletonize_3d:

im = ps.generators.blobs(shape=[250, 250], blobiness=1, porosity=0.6)
sk = skeletonize_3d(im)
sk1 = ps.filters.prune_branches(sk)

fig, ax = plt.subplots(1, 2, figsize=[12, 6])
ax[0].imshow(sk/im, interpolation='none', origin='lower')
ax[0].axis(False)
ax[1].imshow(sk1/im, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/9d138b1c52219b4fc3a0f7273523e2272beeea0d75e65c6da993c2c2cad50260.png

iterations#

How many times to repeat the process. This is equivalen to just calling the function multiple times with the returned image, but is more convenient.

sk1 = ps.filters.prune_branches(sk, iterations=1)
sk2 = ps.filters.prune_branches(sk, iterations=2)
sk3 = ps.filters.prune_branches(sk, iterations=3)

fig, ax = plt.subplots(1, 3, figsize=[15, 5])
ax[0].imshow(sk1/im, interpolation='none', origin='lower')
ax[0].axis(False)
ax[1].imshow(sk2/im, interpolation='none', origin='lower')
ax[1].axis(False)
ax[2].imshow(sk3/im, interpolation='none', origin='lower')
ax[2].axis(False);
../../../_images/405e3cc855dacb53a384a0644536411e2de8d0ac6c137fd8d0d11556d7625c95.png