region_size#

Each voxel is replaced with the size of the region to which it belongs

Import packages#

import matplotlib.pyplot as plt
import numpy as np

import porespy as ps

ps.visualization.set_mpl_style()
np.random.seed(0)

im#

Generate a test image. Can be either 2D or 3D.

im = ps.generators.blobs(shape=[200, 200], porosity=0.4, seed=0)
size = ps.filters.region_size(im=im)

fig, ax = plt.subplots(1, 2, figsize=[8, 4])
ax[0].imshow(im)
ax[0].axis(False)
ax[1].imshow(size)
ax[1].axis(False);
../../../_images/ecdde3aa3f9c27e9b3a4d92a1c0a4f5f5acf35f3b3fd9467efd1c302e108e263.png

We can count the number of voxels belonging to each size cluster using np.unique, but note that the unique values is equal to the number of each unique values, which is the whole point of the filter.

vals, counts = np.unique(size[im], return_counts=True)
print(vals)
print(counts)
[   8   16   18   21   36   47   55   89  114  119  144  147  190  257
  716  784  894 1387 2033 3938 4955]
[   8   48   18   21   36   47   55   89  114  119  144  147  190  257
  716  784  894 1387 2033 3938 4955]
np.sum(size == 8)
8