prtools.binary_erosion#

binary_erosion(input, structure=None, iterations=1, mask=None, output=None, border_value=0)[source]#

Binary erosion using the given structure element.

Parameters:
  • input (array_like) – Array to be eroded. Nonzero elements form the subset to be eroded.

  • structure (array_like, optional) – Structure element used for erosion. Nonzero elements are considered True. If None (default), a structure element with a square connectivity equal to one is used.

  • iterations (int, optional) – Number of times to repeat the erosion. Default is 1.

  • mask (array_like, optional) – Mask applied to the inputs where a True value indicates the corresponding input element should be included in the erosion.

  • output (ndarray, optional) –

    Array location into which the result is stored. If None (default), a freshly-allocated array is returned.

    Note

    output must be None if input is a JAX array.

  • border_value (int (cast to 0 or 1), optional) – Value at the border of the output array.

Returns:

binary_erosion – Erosion of the input by the structure element.

Return type:

ndarray of bools

Notes

This function is designed to be compatible with JAX jit and grad operations.

Examples

>>> a = np.zeros((7,7), dtype=int)
>>> a[1:6, 2:5] = 1
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])

>>> prtools.binary_erosion(a)
array([[False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False,  True, False, False, False],
       [False, False, False,  True, False, False, False],
       [False, False, False,  True, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False]])

>>> prtools.binary_erosion(a).astype(int)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])

>>> # Erosion removes objects smaller than the structure
>>> prtools.binary_erosion(a, structure=np.ones((5,5))).astype(int)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])