prtools.binary_closing#
- binary_closing(input, structure=None, iterations=1, mask=None, output=None, border_value=0)[source]#
Binary closing using the given structure element.
The closing of an input image is the erosion of the dilation of the image by the structure element.
- Parameters:
input (array_like) – Array to be closed. Nonzero elements form the subset to be closed.
structure (array_like, optional) – Structure element used for closing. 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 closing. 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 closing.
output (ndarray, optional) –
Array location into which the result is stored. If None (default), a freshly-allocated array is returned.
Note
outputmust be None ifinputis a JAX array.border_value (int (cast to 0 or 1), optional) – Value at the border of the output array.
- Returns:
binary_closing – Closing of the input by the structure element.
- Return type:
ndarray of bools
See also
Notes
This function is designed to be compatible with JAX
jitandgradoperations.Examples
>>> a = np.zeros((5,5), dtype=int) >>> a[1:-1, 1:-1] = 1; a[2,2] = 0 >>> a array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]) >>> # Closing removes small holes >>> prtools.binary_closing(a).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]])
>>> a = np.zeros((7,7), dtype=int) >>> a[1:6, 2:5] = 1; a[1:3,3] = 0 >>> a array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 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]]) >>> # Closing can also coarsen boundaries with fine hollows >>> prtools.binary_closing(a).astype(int) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 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]])