trim_floating_solid
#
trim_floating_solid
function is a filter which removes solids not attached to primary solid structure.
import numpy as np
import porespy as ps
import scipy.ndimage as spim
import scipy
import matplotlib.pyplot as plt
import skimage
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
im
#
How floating solids are removed and the result can depend on whether the image is 2D or 3D so here we investigate both cases. The 2D and 3D images are visualized but only a slice of the 3D image is shown.
im2d = ps.generators.blobs(shape=[500, 500])
im3d = ps.generators.blobs(shape=[500, 500, 500])
fig, ax = plt.subplots(1, 2, figsize=[12, 12]);
ax[0].imshow(im2d);
ax[0].axis(False);
ax[0].set_title('2D', fontdict={'fontsize': 18});
ax[1].imshow(im3d.take(indices=250, axis=2));
ax[1].axis(False);
ax[1].set_title('3D', fontdict={'fontsize': 18});
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
Cell In[2], line 2
1 im2d = ps.generators.blobs(shape=[500, 500])
----> 2 im3d = ps.generators.blobs(shape=[500, 500, 500])
4 fig, ax = plt.subplots(1, 2, figsize=[12, 12]);
5 ax[0].imshow(im2d);
File ~/work/porespy/porespy/porespy/generators/_imgen.py:1117, in blobs(shape, porosity, blobiness, divs, seed)
1115 else:
1116 im = spim.gaussian_filter(im, sigma=sigma)
-> 1117 im = norm_to_uniform(im, scale=[0, 1])
1118 if porosity:
1119 im = im < porosity
File ~/work/porespy/porespy/porespy/tools/_funcs.py:965, in norm_to_uniform(im, scale)
963 if scale is None:
964 scale = [im.min(), im.max()]
--> 965 im = (im - np.mean(im)) / np.std(im)
966 im = 1 / 2 * erfc(-im / np.sqrt(2))
967 im = (im - im.min()) / (im.max() - im.min())
KeyboardInterrupt:
2D conn
#
conn
options for 2D images are 4 and 8 for square and diagonal neighbours respectively.
x1 = ps.filters.trim_floating_solid(im=im2d, conn=4)
x2 = ps.filters.trim_floating_solid(im=im2d, conn=8)
fig, ax = plt.subplots(1, 2, figsize=[12, 12]);
ax[0].imshow(x1);
ax[0].axis(False);
ax[0].set_title('conn = 4', fontdict={'fontsize': 18});
ax[1].imshow(x2);
ax[1].axis(False);
ax[1].set_title('conn = 8', fontdict={'fontsize': 18});
conn
options for 3D images are 6 and 26 for similarly square and diagonal neighbours. Apparent floating solids in the visualized 2D slice may actually be attached to solid in adjacent 2D slice and therefore may not actually be considered to be a floating solid.
x3 = ps.filters.trim_floating_solid(im=im3d, conn=6)
x4 = ps.filters.trim_floating_solid(im=im3d, conn=26)
fig, ax = plt.subplots(1, 2, figsize=[12, 12]);
ax[0].imshow(x3.take(indices=250, axis=2));
ax[0].axis(False);
ax[0].set_title('conn = 6', fontdict={'fontsize': 18});
ax[1].imshow(x4.take(indices=250, axis=2));
ax[1].axis(False);
ax[1].set_title('conn = 26', fontdict={'fontsize': 18});