# 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 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#

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


## 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:

snow_out = ps.filters.snow_partitioning_parallel(
im=im, divs=2, 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