prune_branches#

Removes dangling branches from a skeleton.

import matplotlib.pyplot as plt
from skimage.morphology import skeletonize

import porespy as ps

ps.visualization.set_mpl_style()

im#

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

im = ps.generators.blobs(shape=[250, 250], blobiness=1, porosity=0.6, seed=0)
sk = skeletonize(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/bb7e2901ee1061c2e5de2f42fb68dbccd17fcafce96087348b474ba4a0cbaa90.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=10)

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/d96ad10ba2abe5ff53ae14a3ec8b7ff123bde6598cf6d3d10ff79cd7abef64ed.png