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()
[18:51:59] 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)
[[ -3   1   9  -2   5  -7   5  -3  -9  -1]
 [  7  -1  -5   3   0   0  -8  -7   9   7]
 [ -6  -4  -7  -4  -2 -10  -2   8   3  -2]
 [  2 -10  -4   6   3   6   5   9   2  -4]
 [  1  -6  -3   3  -4  -4   4   4   3  -8]
 [ -4   1   8  -1   4   0 -10  -7  -3   4]
 [ -3   2  -9  -2   8  -2  -8   9  -9   9]
 [ -7  -5  -3   7  -2   0 -10   9   2   6]
 [  2   6 -10 -10   7   4   9 -10  -6   3]
 [ -7  -1  -7 -10   6   4  -5   8   8   5]]
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()}");