trim_disconnected_blobs#

trim_disconnected_blobs is a function which removes blobs that are not connected to specified inlets. Blobs are any clusters of True voxels, so this can be used to analyze both solid or void phase by inverting the image as needed.

import numpy as np
import porespy as ps
import scipy.ndimage as spim
import scipy
import matplotlib.pyplot as plt
ps.visualization.set_mpl_style()
import inspect
print(inspect.signature(ps.filters.trim_disconnected_blobs))
(im, inlets, strel=None)

im and inlets#

The image contains True values indicating the phase of interest. inlets can be custom created to indicate which blobs to trim.

np.random.seed(0)
im = ps.generators.blobs(shape=[100, 100], porosity=0.4)
inlets = ps.tools.get_border(shape=im.shape, mode='faces')
im2 = ps.filters.trim_disconnected_blobs(im, inlets)

fig, ax = plt.subplots(1, 3, figsize=[15, 5])
ax[0].imshow(im, origin='lower', interpolation='none')
ax[0].axis(False)
ax[1].imshow(inlets, origin='lower', interpolation='none')
ax[1].axis(False)
ax[2].imshow(im2, origin='lower', interpolation='none')
ax[2].axis(False);
../../../_images/abec2b48e1aa9ce203444f4ad9d4b282b36632032fd1c7af2b04c9b21d48dcd6.svg

strel#

A structuring element can be provided to indicate how to determine whether clusters of voxels are connected or not.

strel = ps.tools.ps_round(r=1, ndim=2, smooth=False)
im1 = ps.filters.trim_disconnected_blobs(im, inlets, strel)
strel = ps.tools.ps_rect(w=3, ndim=2)
im2 = ps.filters.trim_disconnected_blobs(im, inlets, strel)

fig, ax = plt.subplots(1, 2, figsize=[12, 6])
ax[0].imshow(im1, origin='lower', interpolation='none')
ax[0].axis(False)
ax[1].imshow(im2, origin='lower', interpolation='none')
ax[1].axis(False);
../../../_images/4f3b9b86302a0a6dbd58725224d4b7b7101438b585745ab09b44c714f1c625ac.svg