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 (ND-array) – 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 ND-array containing sets of slice objects for indexing into im that extract subdivisions of an image. If flatten was True, then this array is flat, suitable for iterating. If flatten was False then the slice objects must be accessed by row, col, layer indices. An ND-array is the preferred container since it’s shape can be easily queried.

Return type

ND-array

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], flatten=True)
>>> print(len(s))
4

Examples

Click here to view online example.