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

ps.visualization.set_mpl_style()

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/0bc0ec77aae6abd1e403985b03481a9ade313c492d426f96e8688732d11f638a.png

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/f58d3ca821578b7c56f9ba7377074bce191d434e3f909d909bc69a153b527992.png

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/58dd8a2ba989aaf100b28b4267174e0b5188ac5805abfb5f2edda83c42e179ab.png