make_contiguous#

Import packages#

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

Generate image for testing#

im = np.random.randint(-10,10, [10,10], int)
print(im)
[[ -7  -3  -9   9  -3  -7  -3   1   4  -5]
 [ -1  -5   0  -2  -8  -3  -3   7  -9   2]
 [ -4  -9  -2   6  -2  -3   3   6  -3   9]
 [  1  -8   3   0  -2  -1  -7   3  -9   6]
 [ -3   5   8   5 -10  -8 -10   3  -2 -10]
 [-10  -4   9   8   5   0 -10  -1   8  -5]
 [  2   5  -2  -8   4  -7   1   1  -4   7]
 [ -4  -4   9   3  -6  -7   2   0  -4   4]
 [ -1  -1   0  -7   6   1  -6  -7   5  -9]
 [ -1   6  -6   4  -1   3  -7  -7 -10  -6]]
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im)
ax.axis(False)
ax.set_title(f"Minimum = {im.min()}");
../../../_images/6d6b1be90f8b35d338ed86257a487352760527b9dccdc0e50fd18c87dad8307f.png

Demonstrate function#

im1 = ps.tools.make_contiguous(im=im, mode='keep_zeros')
fig, ax = plt.subplots(1, 1, figsize=[4, 4]);
ax.imshow(im1)
ax.axis(False)
ax.set_title(f"Minimum = {im1.min()}");
../../../_images/75397e36cc7bd44c66faf9f35ee570e7ddfdd6eb004aa12c2d6386e8fd3e76cd.png