subdivide#

subdivide(im, divs=2, overlap=0)[source]#

Returns slices into an image describing the specified number of sub-arrays.

This function is useful for performing operations on smaller images for memory or speed. Note that for most typical operations this will NOT work, since the image borders would cause artifacts (e.g. distance_transform)

Parameters:
  • im (ndarray) – The image of the porous media

  • divs (scalar or array_like) – The number of sub-divisions to create in each axis of the image. If a scalar is given it is assumed this value applies in all dimensions.

  • overlap (scalar or array_like) – The amount of overlap to use when dividing along each axis. If a scalar is given it is assumed this value applies in all dimensions.

Returns:

slices – An ndarray containing sets of slice objects for indexing into im that extract subdivisions of an image. If flatten was True, then this array is suitable for iterating. If flatten was False then the slice objects must be accessed by row, col, layer indices. An ndarray is the preferred container since its shape can be easily queried.

Return type:

ndarray

See also

chunked_func

Examples

>>> import porespy as ps
>>> import matplotlib.pyplot as plt
>>> im = ps.generators.blobs(shape=[200, 200])
>>> s = ps.tools.subdivide(im, divs=[2, 2])
>>> print(len(s))
4

Click here to view online example.