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()
[03:05:18] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         

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);
/tmp/ipykernel_3383/2563978865.py:2: FutureWarning: `skeletonize_3d` is deprecated since version 0.23 and will be removed in version 0.25. Use `skimage.morphology.skeletonize` instead.
  sk = skeletonize_3d(im)
../../../_images/37ba3fcc9ed83821ddbe63ea98ec9b647783139dcf56874fe5e0c0fe9f029e7e.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);