trim_small_clusters#

trim_small_clusters function is a filter that removes isolated voxels or clusters of a given size or smaller.

import numpy as np
import porespy as ps
import scipy.ndimage as spim
import matplotlib.pyplot as plt
import skimage
ps.visualization.set_mpl_style()
[17:43:22] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         

im#

This function works on 2D and 3D images.

im = ps.generators.blobs(shape=[500, 500], blobiness=5, porosity = 0.5)

plt.figure(figsize=[6,6]);
plt.imshow(im);
plt.axis(False);
../../../_images/cb6f80f40252ee8f96b7cb5b8df9fbbd9b90a85f925e6f12b08f578707869d3a.png

size#

The maximum size of a cluster to trim is varied trying 10, 100, and 500 voxels.

x1 = ps.filters.trim_small_clusters(im, size=10)
x2 = ps.filters.trim_small_clusters(im, size=100)
x3 = ps.filters.trim_small_clusters(im, size=500)

fig, ax = plt.subplots(1, 3, figsize=[18, 18]);
ax[0].imshow(x1);
ax[0].axis(False);
ax[0].set_title('size = 10', fontdict={'fontsize': 18});
ax[1].imshow(x2);
ax[1].axis(False);
ax[1].set_title('size = 100', fontdict={'fontsize': 18});
ax[2].imshow(x3);
ax[2].axis(False);
ax[2].set_title('size = 500', fontdict={'fontsize': 18});
../../../_images/43493bbaefabff53b5d125f3cb425b1c00acf9e6dd3b0a7431a65a88d9e37a83.png