fftmorphology

Applies morphological operations (dilation/erosion/opening/closing) on binary images using scipy’s fast Fourier transform convolution method.

import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
from skimage.morphology import disk
import inspect
ps.visualization.set_mpl_style()
inspect.signature(ps.filters.fftmorphology)
<Signature (im, strel, mode='opening')>

im

The input image is a binary image, with True (or 1) values indicating the phase on which the morphological operation is performed.

np.random.seed(10)
im = ps.generators.blobs(shape=[500,500])
fig, ax = plt.subplots(1, 1, figsize=[12, 5])
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/cb38ff9be0660e8da09380374251c683eac996520fc00b4564fe4b04f2b27ede.svg

strel

The structuring element to use for the morphological operation. Note that for a 2D and 3D images, the strucuring elements must be 2D and 3D, respectively. By default the fftmorphology operation is morphological opening.

im_opening = ps.filters.fftmorphology(im, strel=disk(5))
im_diff=im_opening*1.0-im
fig, ax = plt.subplots(1, 3, figsize=[15, 5])
ax[0].imshow(im, origin='lower', interpolation='none')
ax[0].axis(False)
ax[1].imshow(im_opening, origin='lower', interpolation='none')
ax[1].axis(False)
ax[2].imshow(im_diff, origin='lower', interpolation='none')
ax[2].axis(False);
../../../_images/f42374064210c83912c3021148f3fe4a5471bac6e6883ab542dbb2f465934e2e.svg

mode

By default the fftmorphology operation is morphological opening. Let’s try different operations:

im_opening = ps.filters.fftmorphology(im, strel=disk(5))
im_closing = ps.filters.fftmorphology(im, strel=disk(5), mode='closing')
im_erosion = ps.filters.fftmorphology(im, strel=disk(5), mode='erosion')
im_dilation = ps.filters.fftmorphology(im, strel=disk(5), mode='dilation')
fig, ax = plt.subplots(1, 5, figsize=[15, 5])
ax[0].imshow(im, origin='lower', interpolation='none')
ax[0].set_title('original')
ax[0].axis(False)
ax[1].imshow(im_opening, origin='lower', interpolation='none')
ax[1].set_title('opening')
ax[1].axis(False)
ax[2].imshow(im_closing, origin='lower', interpolation='none')
ax[2].set_title('closing')
ax[2].axis(False);
ax[3].imshow(im_erosion, origin='lower', interpolation='none')
ax[3].set_title('erosion')
ax[3].axis(False);
ax[4].imshow(im_dilation, origin='lower', interpolation='none')
ax[4].set_title('dilation')
ax[4].axis(False);
../../../_images/03c46149f9829bde2f0d2879b5fe2fec6d8ddbee46539aeab0fd85ee6ef731f4.svg