porespy.filters.fftmorphology#
- porespy.filters.fftmorphology(im, strel, mode='opening')#
Perform morphological operations on binary images using fft approach for improved performance
- Parameters:
im (ndarray) – The binary image on which to perform the morphological operation
strel (ndarray) – The structuring element to use. Must have the same dims as
im.mode (string) – The type of operation to perform. Options are ‘dilation’, ‘erosion’, ‘opening’ and ‘closing’.
- Returns:
image – A copy of the image with the specified moropholgical operation applied using the fft-based methods available in
scipy.signal.fftconvolve.- Return type:
ndarray
Notes
This function uses
scipy.signal.fftconvolvewhich can be more than 10x faster than the standard binary morphology operation inscipy.ndimage. This speed up may not always be realized, depending on the scipy distribution used.Examples
>>> import porespy as ps >>> from numpy import array_equal >>> import scipy.ndimage as spim >>> from skimage.morphology import disk >>> im = ps.generators.blobs(shape=[100, 100], porosity=0.8)
Check that erosion, dilation, opening, and closing are all the same as the
scipy.ndimagefunctions:>>> result = ps.filters.fftmorphology(im, strel=disk(5), mode='erosion') >>> temp = spim.binary_erosion(im, structure=disk(5)) >>> array_equal(result, temp) True
>>> result = ps.filters.fftmorphology(im, strel=disk(5), mode='dilation') >>> temp = spim.binary_dilation(im, structure=disk(5)) >>> array_equal(result, temp) True
>>> result = ps.filters.fftmorphology(im, strel=disk(5), mode='opening') >>> temp = spim.binary_opening(im, structure=disk(5)) >>> array_equal(result, temp) True
>>> result = ps.filters.fftmorphology(im, strel=disk(5), mode='closing') >>> temp = spim.binary_closing(im, structure=disk(5)) >>> array_equal(result, temp) True