make_contiguous#

Import packages#

import matplotlib.pyplot as plt
import numpy as np

import porespy as ps

ps.visualization.set_mpl_style()

Generate image for testing#

im = np.random.randint(-10, 10, [10, 10], int)
print(im)
[[ -6  -4   7  -1   2  -3   0   5   3  -3]
 [ -8   0   0  -9   7   2  -6  -6   8  -8]
 [ -4   1  -9   6  -1  -3  -5   4  -3  -1]
 [  1   6  -9  -7  -5 -10 -10   3   6  -2]
 [  1   4 -10   1  -7   4  -6   4  -1   9]
 [ -3  -1  -2  -6   2  -4   2   7   0  -1]
 [  2   7  -3  -5   4  -9   7  -4 -10   2]
 [  2   0   2  -8   4   9   7   0   9   0]
 [ -9  -8   2  -6   9  -1   9   6   5   9]
 [ -6   2  -1  -8   5   0   4  -1  -7  -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()}");