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