subdivide

subdivide(im, divs=2, block_size=None, overlap=0, mode='offset')[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. If block_size is given this is ignored.

  • block_size (scalar or array_like) – The size of the divisions to create. If a scalar is given then cubic blocks are created. If this argument is given then divs is ignored.

  • 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.

  • mode (str) –

    This argument is only used if block_size is given and it controls how to handle the situation when block sizes is not a clean multiple of the image shape. The options are:

    mode

    description

    ’whole’

    Blocks start at the beginning of each axis, and only “whole” blocks (that fit within the image) are included in the returned list of slice objects.

    ’offset’

    Only whole blocks are included, but an offset is applied to the start of each axis so that an equal amount of voxels are missed at the start and end of each axis.

    ’partial’

    Blocks start at the beginning of each axis, and any blocks which partially extend beyond the end of the image are returned.

    ’strict’

    Raises an Exception of the image cannot be evenly divided by the given block size.

Returns:

slices – An ndarray containing sets of slice objects for indexing into im that extract subdivisions of an image.

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.