SNOW partitioning parallel

The filter is used to perform SNOW algorithm in parallel and serial mode to save computational time and memory requirement respectively. SNOW algorithm converts a binary image in to partitioned regions while avoiding oversegmentation. SNOW_partitioning_parallel speeds up this process by decomposing the domain into several subdomains and either process them in different cores in parallel to save time or one by one in single core to save memory requirements.

Import Modules

[1]:
import numpy as np
import porespy as ps
from porespy.tools import randomize_colors
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
gs = gridspec.GridSpec(2, 4)
gs.update(wspace=0.5)
np.random.seed(10)
ps.visualization.set_mpl_style()

Create a random image of overlapping spheres

[2]:
im = ps.generators.overlapping_spheres([1000, 1000], r=10, porosity=0.5)
fig, ax = plt.subplots()
ax.imshow(im, origin='lower');
../../../_images/examples_filters_tutorials_snow_partitioning_parallel_4_0.svg

Apply SNOW_partitioning_parallel on the binary image

[3]:
snow_out = ps.filters.snow_partitioning_parallel(
    im=im, divs=2, r_max=5, sigma=0.4)

Plot output results

[4]:
fig, ax = plt.subplots(1, 3, figsize=[9, 3])
ax[0].imshow(snow_out.im);
ax[1].imshow(snow_out.dt);
ax[2].imshow(randomize_colors(snow_out.regions));
ax[0].set_title('Binary Image');
ax[1].set_title('Euclidean Distance Transform')
ax[2].set_title('Segmented Image');
../../../_images/examples_filters_tutorials_snow_partitioning_parallel_8_0.svg
[5]:
print(f"Number of regions: {snow_out.regions.max()}")
Number of regions: 1006