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()
/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
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);

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);
