extract_subsection#

extract_subsection(im, shape)[source]#

Extracts the middle section of a image

Parameters:
  • im (ndarray) – Image from which to extract the subsection

  • shape (array_like) – Can either specify the size of the extracted section or the fractional size of the image to extact.

Returns:

image – An ndarray of size given by the shape argument, taken from the center of the image.

Return type:

ndarray

See also

unpad

Examples

>>> import numpy as sp
>>> from porespy.tools import extract_subsection
>>> im = np.array([[1, 1, 1, 1], [1, 2, 2, 2], [1, 2, 3, 3], [1, 2, 3, 4]])
>>> print(im)
[[1 1 1 1]
 [1 2 2 2]
 [1 2 3 3]
 [1 2 3 4]]
>>> im = extract_subsection(im=im, shape=[2, 2])
>>> print(im)
[[2 2]
 [2 3]]

Click here to view online example.