<jupyter_start><jupyter_text>`fftmorphology`  Applies morphological operations (dilation/erosion/opening/closing) on binary images using scipy's fast Fourier transform convolution method.<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
from skimage.morphology import disk
import inspect
inspect.signature(ps.filters.fftmorphology)<jupyter_output><empty_output><jupyter_text>`im`The input image is a binary image, with `True` (or 1) values indicating the phase on which the morphological operation is performed.<jupyter_code>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);<jupyter_output><empty_output><jupyter_text>`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.<jupyter_code>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);<jupyter_output><empty_output><jupyter_text>`mode` By default the `fftmorphology` operation is morphological opening. Let's try different operations:<jupyter_code>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);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1555190808370948, 'fraction_numerical': 0.022979072630283134, 'mean_word_length': 8.991803278688524, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '66338', 'license': 'MIT', 'n_tokens_mistral': 901, 'n_tokens_neox': 847, 'n_words': 178, 'path': 'examples/filters/reference/fftmorphology.ipynb', 'repo_name': 'xu-kai-xu/porespy', 'size': '2437'}