erode#

Erodes 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.erode)
<Signature (im: NDArray, r: int, dt: NDArray = None, method: str = 'dt', smooth: bool = True)>

im#

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

im = ps.generators.blobs(shape=[200, 200], porosity=0.6, seed=0)
ero = ps.filters.erode(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(ero, origin='lower', interpolation='none')
ax[1].set_title('eroded, r = 3')
ax[1].axis(False);
../../../_images/f3fdd678913e9c639ea038d62ab320edd24ad2881934f5f724732c44388dae4f.png

r#

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

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

method#

Three implementations are available:

  • 'dt' (default) uses the distance transform of the foreground to remove voxels within r of the background.

  • 'conv' uses FFT-based convolution with a round structuring element.

  • 'brute_force' (alias 'bf') draws disks or spheres centered on background interface voxels, then inverts the result to erode the foreground. It uses the shared optimized sphere-drawing routines without computing a distance transform.

The brute-force method supports 2D and 3D images and requires a nonnegative integer radius. It respects the smooth setting, and the dt argument is only used by the distance-transform method.

ero_dt = ps.filters.erode(im=im, r=4, method='dt')
ero_conv = ps.filters.erode(im=im, r=4, method='conv')
ero_bf = ps.filters.erode(im=im, r=4, method='brute_force')

fig, ax = plt.subplots(1, 3, figsize=[15, 5])
for axis, result, method in zip(ax, [ero_dt, ero_conv, ero_bf],
                                ['dt', 'conv', 'brute_force']):
    axis.imshow(result, origin='lower', interpolation='none')
    axis.set_title(f"method = '{method}'")
    axis.axis(False)
../../../_images/caeaffac11a28ff9bda0c8b9e8e8ea85d8f68914f75a05fff05e353be9473244.png

smooth#

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

ero_smooth = ps.filters.erode(im=im, r=5, smooth=True)
ero_rough = ps.filters.erode(im=im, r=5, smooth=False)

fig, ax = plt.subplots(1, 2, figsize=[10, 5])
ax[0].imshow(ero_smooth, origin='lower', interpolation='none')
ax[0].set_title('smooth = True')
ax[0].axis(False)
ax[1].imshow(ero_rough, origin='lower', interpolation='none')
ax[1].set_title('smooth = False')
ax[1].axis(False);
../../../_images/00b7ca040d926d37b5294a051561cd8d823cc0babeb73497d3d198c17d5bccfe.png

dt#

If the distance transform of the foreground 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 = get_edt()(im)
ero = ps.filters.erode(im=im, r=4, dt=dt)