make_contiguous

Import packages

[1]:
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

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

Demonstrate function

[4]:
im1 = ps.tools.make_contiguous(im=im, mode='keep_zeros')
[5]:
fig, ax = plt.subplots(1, 1, figsize=[4, 4]);
ax.imshow(im1)
ax.axis(False)
ax.set_title(f"Minimum = {im1.min()}");
../../../_images/examples_tools_howtos_make_contiguous_8_0.svg