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()
[19:54:36] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         
No module named 'pyedt'

Generate image for testing

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

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()}");