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