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)
[[  8 -10  -4  -9   0   0  -2  -6  -9   8]
 [ -3   6   3   5  -1   3   1  -8   9   5]
 [ -4   6  -6 -10  -7   8   2   4  -1  -9]
 [ -4  -6  -7  -5  -3   7  -3   5  -3   4]
 [-10   6   4   8  -6   7  -7  -6  -9  -8]
 [  4   3  -4   9   5   3  -6   1  -6   4]
 [  4   5   6  -5   5   5  -1   0  -1  -3]
 [  3  -8  -5   6  -4   8  -7  -8   5  -8]
 [  2   5  -8  -5  -8  -8   0   6   4   4]
 [  4   9   4   1   5  -6   8 -10   9 -10]]
[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_reference_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_reference_make_contiguous_8_0.svg