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  -5  -2  -4   2   4   1  -1  -5  -4]
 [  7   0  -4  -4  -2  -7 -10  -1   2   0]
 [  6   5   0  -7 -10   3   4  -5  -2  -2]
 [  5  -7   1  -7  -2   1  -6   0   5   8]
 [ -2   4  -2  -3   2 -10   7  -7   6   8]
 [  7 -10  -6   4 -10  -7  -8   8 -10  -6]
 [ -8  -7  -6  -8  -8   4   5 -10  -1  -6]
 [ -8  -6 -10   3   9 -10   5   1   4   4]
 [  5   1   1  -1  -3  -3  -6   4 -10  -3]
 [  3   9  -1   4  -7   3   9  -7   6  -8]]
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im)
ax.axis(False)
ax.set_title(f"Minimum = {im.min()}");
../../../_images/ce381c35af7d7d9e93b67f119ccfffebb2c2e03999eb325dec106451a7e583cb.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/1b63d47163243c63466dcfea7e44a1d1d5fad567b1ffda91de54e6333013c3ce.png