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
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/openpnm/algorithms/ 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 for details.
  def _find_trapped_pores(inv_seq, indices, indptr, outlets):  # pragma: no cover
import inspect
(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.

im = ps.generators.blobs(shape=[100, 100], porosity=0.4)
inlets =, 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[1].imshow(inlets, origin='lower', interpolation='none')
ax[2].imshow(im2, origin='lower', interpolation='none')


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

strel =, ndim=2, smooth=False)
im1 = ps.filters.trim_disconnected_blobs(im, inlets, strel)
strel =, 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[1].imshow(im2, origin='lower', interpolation='none')