dilate#

Dilates the foreground of a boolean image with a round structuring element of radius r.

import matplotlib.pyplot as plt

import porespy as ps

ps.visualization.set_mpl_style()

The arguments and their defaults are:

import inspect

inspect.signature(ps.filters.dilate)
<Signature (im: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], r: int, dt: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]] = None, method: str = 'dt', smooth: bool = True)>

im#

A boolean image with the foreground (the phase to be dilated) marked as True. Both 2D and 3D images are supported.

im = ps.generators.blobs(shape=[200, 200], porosity=0.5, seed=0)
dil = ps.filters.dilate(im=im, r=3)

fig, ax = plt.subplots(1, 2, figsize=[10, 5])
ax[0].imshow(im, origin='lower', interpolation='none')
ax[0].set_title('original')
ax[0].axis(False)
ax[1].imshow(dil, origin='lower', interpolation='none')
ax[1].set_title('dilated, r = 3')
ax[1].axis(False);

r#

Radius of the round structuring element, in voxels. Larger values dilate further.

fig, ax = plt.subplots(1, 3, figsize=[15, 5])
for axis, r in zip(ax, [1, 3, 6]):
    dil = ps.filters.dilate(im=im, r=r)
    axis.imshow(dil, origin='lower', interpolation='none')
    axis.set_title(f'r = {r}')
    axis.axis(False)

method#

Two equivalent implementations are available. 'dt' (default) finds all voxels within r of the foreground using the distance transform of the background; 'conv' finds them by FFT-based convolution against a round structuring element. Results are equivalent.

dil_dt = ps.filters.dilate(im=im, r=4, method='dt')
dil_conv = ps.filters.dilate(im=im, r=4, method='conv')

fig, ax = plt.subplots(1, 2, figsize=[10, 5])
ax[0].imshow(dil_dt, origin='lower', interpolation='none')
ax[0].set_title("method = 'dt'")
ax[0].axis(False)
ax[1].imshow(dil_conv, origin='lower', interpolation='none')
ax[1].set_title("method = 'conv'")
ax[1].axis(False);

smooth#

When True (default) a single-voxel protrusion on the face of the structuring element is removed, which gives visibly rounder boundaries. Set to False to keep the bare digital sphere.

dil_smooth = ps.filters.dilate(im=im, r=5, smooth=True)
dil_rough = ps.filters.dilate(im=im, r=5, smooth=False)

fig, ax = plt.subplots(1, 2, figsize=[10, 5])
ax[0].imshow(dil_smooth, origin='lower', interpolation='none')
ax[0].set_title('smooth = True')
ax[0].axis(False)
ax[1].imshow(dil_rough, origin='lower', interpolation='none')
ax[1].set_title('smooth = False')
ax[1].axis(False);

dt#

If the distance transform of the background is already available it can be passed in to avoid recomputing it. This argument only matters when method='dt'.

from porespy.tools import get_edt

dt_bg = get_edt()(~im)
dil = ps.filters.dilate(im=im, r=4, dt=dt_bg)