extract_subsection

Import packages

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

[9]:
im = np.random.rand(100, 100)
fig, ax = plt.subplots(figsize=[4, 4])
ax.axis(False)
ax.imshow(im)
[9]:
<matplotlib.image.AxesImage at 0x7f361a742100>
../../../_images/examples_tools_howtos_extract_subsection_4_1.svg

Demonstration

This tool was designed to ‘uppad’ an image that has had an equal amount of padding applied to all sides. The arguments assume that you know the original size of the image and wish to retrieve it back:

[13]:
im2 = np.pad(im, pad_width=20, constant_values=0)
im = ps.tools.extract_subsection(im=im2, shape=im.shape)
fig, ax = plt.subplots(1, 2, figsize=[8, 4])
ax[0].axis(False)
ax[0].imshow(im2);
ax[1].axis(False)
ax[1].imshow(im);
../../../_images/examples_tools_howtos_extract_subsection_6_0.svg