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 matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
from porespy.tools import randomize_colors
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#
Apply SNOW_partitioning_parallel on the binary image#
Parallelization is done by dividing the image into chunks and processes each separately. The results are stitched back together to make a full image. The process is explored and explained in our publication in Advances in Water Resources. There is a dedicated function in porespy.filters
for this. Settings divs=2
means a 2D images is divided into two chunks in each direction for a total of 4:
The parallel_kw
dictionary is used to set the settings for parallelization. If not provided, the default values will be used or porespy.settings
will be used to set arguments for parallelization.
parallel_kw = {"divs": 2}
snow_out = ps.filters.snow_partitioning_parallel(
im=im, parallel_kw=parallel_kw, r_max=5, sigma=0.4)
The result will be indentical to the serial version if sufficient overlap was chosen between the chunks. There is an automated computation of this overap in the function. The results are shown below:
fig, ax = plt.subplots(1, 1, figsize=[6, 6])
ax.imshow(randomize_colors(snow_out.regions))
ax.set_title('Segmented Image');
print(f"Number of regions: {snow_out.regions.max()}")
Number of regions: 980