flood_func#

Floods the regions of an image with values computed by the supplied numpy function.

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

The arguments and their default values are:

import inspect
inspect.signature(ps.filters.flood_func)
<Signature (im, func, labels=None)>

func#

The function can be anything in numpy that operates on an array. For instance, when passing in the np.sum function it will compute the sum of voxels with each regions and replace those values with the sum. This allows for the determination of a regions size. Or, if the supplied image is the distance transform the np.amax function can be supplied to color each region by the maximum size found within it.

fig, ax = plt.subplots(1, 2, figsize=[6, 3])

im = ~ps.generators.overlapping_spheres(shape=[200, 200], porosity=0.5, r=10)
flooded = ps.filters.flood_func(im=im, func=np.sum)

ax[0].imshow(flooded)
ax[0].axis(False)
ax[0].set_title('np.sum')

dt = edt(im)
flooded = ps.filters.flood_func(im=dt, func=np.amax)
ax[1].imshow(flooded)
ax[1].axis(False)
ax[1].set_title('np.amax');
../../../_images/b504f59edd6325762b2abdd8cddc72939f211a8d6e7fd9efaa4d510e5573927a.png

labels#

An image with each region of interest labelled. If not provided the scipy.ndimage.label function is applied.

im = ps.generators.overlapping_spheres(shape=[200, 200], porosity=0.5, r=10)
dt = edt(im)
dt = spim.gaussian_filter(dt, sigma=0.4)
pk = ps.filters.find_peaks(dt=dt)
ws = watershed(-dt, markers=spim.label(pk)[0])

flooded = ps.filters.flood_func(im=im, labels=ws, func=np.sum)*im

fig, ax = plt.subplots(1, 1, figsize=[6, 3])
ax.imshow(flooded)
ax.axis(False)
ax.set_title('np.sum');
../../../_images/dba63b5f33b383f2bbce1c348b8dd7981d77be5461e5aa0cd9cbbc0fbfdb3558.png