footprint_rectangle#
- mufasa.utils.neighbours.footprint_rectangle(shape, *, dtype=<class 'numpy.uint8'>, decomposition=None)[source]#
Generate a rectangular or hyper-rectangular footprint.
Generates, depending on the length and dimensions requested with shape, a square, rectangle, cube, cuboid, or even higher-dimensional versions of these shapes.
- Parameters:
shape (tuple[int, ...]) – The length of the footprint in each dimension. The length of the sequence determines the number of dimensions of the footprint.
dtype (data-type, optional) – The data type of the footprint.
decomposition ({None, 'separable', 'sequence'}, optional) – If None, a single array is returned. For ‘sequence’, a tuple of smaller footprints is returned. Applying this series of smaller footprints will give an identical result to a single, larger footprint, but often with better computational performance. See Notes for more details. With ‘separable’, this function uses separable 1D footprints for each axis. Whether ‘sequence’ or ‘separable’ is computationally faster may be architecture-dependent.
- Returns:
footprint – A footprint consisting only of ones, i.e. every pixel belongs to the neighborhood. When decomposition is None, this is just an array. Otherwise, this will be a tuple whose length is equal to the number of unique structuring elements to apply (see Examples for more detail).
- Return type:
Examples
>>> import skimage as ski >>> ski.morphology.footprint_rectangle((3, 5)) array([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]], dtype=uint8)
Decomposition will return multiple footprints that combine into a simple footprint of the requested shape.
>>> ski.morphology.footprint_rectangle((9, 9), decomposition="sequence") ((array([[1, 1, 1], [1, 1, 1], [1, 1, 1]], dtype=uint8), 4),)
“sequence” makes sure that the decomposition only returns 1D footprints.
>>> ski.morphology.footprint_rectangle((3, 5), decomposition="separable") ((array([[1], [1], [1]], dtype=uint8), 1), (array([[1, 1, 1, 1, 1]], dtype=uint8), 1))
Generate a 5-dimensional hypercube with 3 samples in each dimension
>>> ski.morphology.footprint_rectangle((3,) * 5).shape (3, 3, 3, 3, 3)