unpad#

Import packages#

import porespy as ps
import numpy as np
import matplotlib.pyplot as plt
from porespy.tools import get_border, extend_slice, extract_subsection
ps.visualization.set_mpl_style()
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/openpnm/algorithms/_invasion_percolation.py:358: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  def _find_trapped_pores(inv_seq, indices, indptr, outlets):  # pragma: no cover

Generate image for testing#

im = ps.generators.blobs([100,150], porosity = 0.3)
fig, ax = plt.subplots(figsize=[4, 4])
ax.imshow(im)
ax.axis(False);
../../../_images/616f6e389dc6655ccb310abc9261c0c8eed5ff19973e85e74401ec5390361f84.png

Apply tool#

This should be a standard part of numpy, perhaps numpy.pad(pad_width, mode='remove'), but it’s not:

pad_width = [10, 30]
print("shape original:", im.shape)
im1 = np.pad(im, pad_width, mode = "constant", constant_values = 1)
print("shape padded:", im1.shape)
im3 = ps.tools.unpad(im1, pad_width)
print("shape new unpad:", im3.shape)

fig, ax = plt.subplots(1, 3, figsize=[8, 4]);
ax[0].imshow(im);
ax[1].imshow(im1);
ax[2].imshow(im3);
ax[0].set_title('image')
ax[1].set_title('pad added')
ax[2].set_title('pad removed');
shape original: (100, 150)
shape padded: (140, 190)
shape new unpad: (100, 150)
../../../_images/b60b2f71295d4161c7faffd42a3822119707952d8363b433082f77c984fa081c.png