prtools.binary_dilation#

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

Binary dilation using the given structure element.

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

  • structure (array_like, optional) – Structure element used for dilation. 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 dilation. 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 dilation.

  • 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_dilation – Dilation 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((5,5), dtype=int)
>>> a[2,2] = 1
>>> a
array([[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]])

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

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

>>> prtools.binary_dilation(a, iterations=2).astype(int)
array([[0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0],
       [1, 1, 1, 1, 1],
       [0, 1, 1, 1, 0],
       [0, 0, 1, 0, 0]])

>>> prtools.binary_dilation(a, structure=np.ones((3,3))).astype(int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])