find_disconnected_voxels

Detects the isolated regions that are not connected to the edges of the image. This function uses the label method in scipy ndimage with a specific structuring element to find the disconnected voxels. A cluster of connected pixels or isolated pixels are labeled with a unique value. Then a scikitimage clear_border filter is applied on the labeled regions to remove the regions that are connected to the borders of the image. The resulting filtered image includes the isolated regions that are disconnected from the edges of the image.

import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import inspect
ps.visualization.set_mpl_style()
inspect.signature(ps.filters.find_disconnected_voxels)
<Signature (im: numpy.ndarray[typing.Any, numpy.dtype[+_ScalarType_co]], conn: Literal['min', 'max'] = 'max', surface: bool = False)>

im

The input image is a binary image, with True (or 1) values indicating the phase for which disconnected voxels are to be found.

np.random.seed(10)
im = ps.generators.blobs(shape=[200,200])
discon_voxels = ps.filters.find_disconnected_voxels(im=im)
fig, ax = plt.subplots(1, 2, figsize=[12, 5])
ax[0].imshow(im, origin='lower', interpolation='none')
ax[0].axis(False)
ax[1].imshow(discon_voxels, origin='lower', interpolation='none')
ax[1].axis(False);

conn

Controls how ‘connected’ a group of voxels must be. The options are 'min' which means voxels are only considered connected if they share a face, and 'max' which means voxels are connected if they share a face, edge or corner.

discon_voxels = ps.filters.find_disconnected_voxels(im=im, conn='min')
fig, ax = plt.subplots(1, 1, figsize=[6, 6])
ax.imshow(discon_voxels, origin='lower', interpolation='none')
ax.axis(False);

surface

Bt default, this Boolean parameter is False. If True any isolated regions touching the edge of the image are considered disconnected.

discon_voxels = ps.filters.find_disconnected_voxels(im=im, surface=True)
fig, ax = plt.subplots(1, 1, figsize=[6, 6])
ax.imshow(discon_voxels, origin='lower', interpolation='none')
ax.axis(False);