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)
[[ -2  -7  -2  -2   2   4   8   0   0  -9]
 [  5  -3   3   5   9  -1  -7   5 -10   7]
 [  6   0   2  -2  -7   8  -6 -10   4   5]
 [  8  -8 -10  -3  -2  -4  -2 -10  -5  -9]
 [-10 -10   9  -3  -8  -7   2  -2   6   9]
 [  5   7  -9   3   1   7  -6  -5   9 -10]
 [  3  -9   1   2  -1  -1  -9  -8   2  -7]
 [  9   1  -3   5   0 -10   9  -9   5  -5]
 [ -5 -10   4  -1  -2  -5  -5  -8   5  -7]
 [  3  -6  -2  -5   2   0   6 -10   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/6c8fc0abea8d3f5dbeaec26dc4edfb0b9f82a120cb5257f3469c4459f36e285f.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/57b841d3fcd99ea16576969225a37c071916ee620ac322f7f2443a975156594d.png