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()
[17:45:13] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         

Generate image for testing#

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