make_contiguous#

Import packages#

import numpy as np
import porespy as ps
import scipy.ndimage as spim
import matplotlib.pyplot as plt
import skimage
ps.visualization.set_mpl_style()

Generate image for testing#

im = np.random.randint(-10,10, [10,10], int)
print(im)
[[  8   9  -6   8  -5   2  -8  -2  -3  -2]
 [ -1  -7  -7  -6   6   4   1   6   6   7]
 [  3  -7  -6   7   2  -3 -10   6  -3 -10]
 [ -2   1  -4 -10  -2   0  -3 -10   2   8]
 [  4   7   0   1   7   2  -7  -3   2   1]
 [ -2  -5   8  -6   6  -8   3 -10   8  -1]
 [ -4   2   7   4   4  -3   6   8   5  -7]
 [ -2   0  -9  -1  -7   5  -9   0   7   4]
 [  6  -1   2   8   1   2  -1  -1   7  -6]
 [  3  -7 -10 -10   5   1   5   6   9   6]]
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im)
ax.axis(False)
ax.set_title(f"Minimum = {im.min()}");
../../../_images/da4186ebf4559d4069adb1267d788b58c849db55a21c883b9c9160d6337d8691.svg

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/70a1db74f251f1a3fb8c283b39e4cf4438185598e58fa910eee8e7b13f09bcc4.svg