trim_nearby_peaks#

trim_nearby_peaks function is a filter which finds nearby peaks in an image and removes the peak that is closer to the solid phase. This filter relies on the distance transform of an image.

import numpy as np
import porespy as ps
import scipy.ndimage as spim
import matplotlib.pyplot as plt
import skimage
from edt import edt
ps.visualization.set_mpl_style()
[17:46:44] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         

dt#

The distance transform of a test image is determined using the edt method.

im = ps.generators.blobs(shape=[200, 200])
dt = edt(im)

plt.figure(figsize=[6, 6])
plt.imshow(dt/im)
plt.axis(False);
../../../_images/a6b5da6b7c4a2e4047374a306878d6aae1dfb10537ec548a63c05a853370c7e4.png

peaks#

The peaks of the distance transform are found using the find_peaks filter and nearby peaks are removed.

peaks = ps.filters.find_peaks(dt, r_max=4)

x = ps.filters.trim_nearby_peaks(peaks=peaks, dt=dt)

fix, ax = plt.subplots(1, 2, figsize=[12, 12])
ax[0].axis(False)
ax[0].imshow(peaks/im)
ax[0].set_title('Before', fontdict={'fontsize': 18});
ax[1].axis(False)
ax[1].imshow(x/im);
ax[1].set_title('After', fontdict={'fontsize': 18});
../../../_images/0fc31d7bbc7e48866827295da3406da91a50045fcc449917de8ca77d2e96fb83.png