skimage2.morphology.footprint_rectangle_decomposed#

skimage2.morphology.footprint_rectangle_decomposed(shape, *, method='separable', dtype=<class 'numpy.uint8'>)[source]#

Generate a (hyper-)rectangular decomposed 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:
shapetuple[int, â€Ķ]

The length of the footprint in each dimension. The length of the sequence determines the number of dimensions of the footprint.

dtypedata-type, optional

The data type of the footprint.

method{‘separable’, ‘sequence’}, optional

With ‘separable’ (the default), this function generates separable 1D footprints for each axis. ‘sequence’ will try to decompose into a sequence of more compact footprints. It is only supported for footprints with an odd length in each dimension and will fall back to ‘separable’. Whether ‘sequence’ or ‘separable’ is computationally faster may be architecture-dependent.

Returns:
footprinttuple[tuple[ndarray, int], â€Ķ]

A footprint consisting of a tuple whose length is equal to the number of unique structuring elements to apply. Each entry of the tuple is another 2-element tuple containing a footprint followed by the number of times it should be applied.

See also

footprint_rectangle

Alternate version that creates a “dense” footprint.

numpy.ones

Upstream version that creates a “dense” footprint.

Examples

Decomposition will return multiple smaller footprints that can be used instead of a conventional “dense” footprint:

>>> import _skimage2 as ski2
>>> decomposed = ski2.morphology.footprint_rectangle_decomposed((3, 5))
>>> decomposed
((array([[1],
         [1],
         [1]], dtype=uint8),
  1),
 (array([[1, 1, 1, 1, 1]], dtype=uint8), 1))

Use this as you would use a “dense” footprint with any function in the library that accepts a footprint. For example, dilating an array with a single pixel in the middle with the decomposed footprint reveals the composed shape of the footprint:

>>> dirac = np.zeros((7, 7), dtype=np.uint8)
>>> dirac[3, 3] = 1
>>> ski2.morphology.dilation(dirac, footprint=decomposed)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

This is effectively what footprint_from_sequence does under the hood.

You can also try method='sequence' which will try to generate a more compact decomposition.

>>> ski2.morphology.footprint_rectangle_decomposed((3, 5), method="sequence")
((array([[1, 1, 1],
         [1, 1, 1],
         [1, 1, 1]], dtype=uint8),
  1),
 (array([[1, 1, 1]], dtype=uint8), 1))

This can be faster than the default method='separable' but is only supported with footprints of odd length.