SNOW partitioning#

The filter is used to partition an image into regions using the SNOW algorithm which stands for the subnetwork of the oversegmented watershed. The steps taken are described in detail in the snow_advanced notebook. We provide a filter function that combines all the steps and it is explored here:

import matplotlib.pyplot as plt
import numpy as np
from skimage.morphology import binary_dilation

import porespy as ps

ps.visualization.set_mpl_style()
np.random.seed(1)
im = ps.generators.overlapping_spheres([500, 500], r=10, porosity=0.5)
fig, ax = plt.subplots()
ax.imshow(im, origin="lower");
../../../_images/cd3acadba3fe92823c59d39b44a56cb6eeac5d25e6e7dffd78a592d1f2057ba4.png
snow_out = ps.filters.snow_partitioning(im, r_max=4, sigma=0.4)
print(snow_out)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Results of snow_partitioning generated at Sun Nov  8 04:27:05 2026
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
im                        Array of size (500, 500)
dt                        Array of size (500, 500)
peaks                     Array of size (500, 500)
regions                   Array of size (500, 500)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
fig, ax = plt.subplots(2, 2, figsize=[8, 8])
ax[0, 0].imshow(snow_out.im, origin="lower")
ax[0, 1].imshow(snow_out.dt, origin="lower")
dt_peak = snow_out.dt.copy()
peaks_dilated = binary_dilation(snow_out.peaks > 0)
dt_peak[peaks_dilated > 0] = np.nan
ax[1, 0].imshow(dt_peak, origin="lower")
ax[1, 1].imshow(ps.tools.randomize_colors(snow_out.regions), origin="lower")
ax[0, 0].set_title("Binary image")
ax[0, 1].set_title("Distance transform")
ax[1, 0].set_title("Distance transform peaks")
ax[1, 1].set_title("Segmentation");
/tmp/ipykernel_130933/2405083734.py:5: FutureWarning: `binary_dilation` is deprecated since version 0.26 and will be removed in version 0.28. Use `skimage.morphology.dilation` instead. Note the lack of mirroring for non-symmetric footprints (see docstring notes).
  peaks_dilated = binary_dilation(snow_out.peaks > 0)
../../../_images/cb9b638ea02e0a4c48fba5600103c05053d6c942bf20ac70868c6c713b1bb6a9.png