nanshe.imp.filters.masks module¶
The masks
module provides filters for working with binary images.
Overview¶
Functions provided include binary dilation and erosion. These allow for N-D array processing.
API¶
-
nanshe.imp.filters.masks.
binary_dilation
(*args, **kwargs)[source]¶ Performs simple binary dilation on a bool array of arbitrary dimension.
Parameters: - input_array (numpy.ndarray) – the bool array to perform dilation on.
- footprint (numpy.ndarray) – the footprint to use for the kernel.
- out (numpy.ndarray) – a place to store the result if provided. (optional)
Returns: - Same as out if out was
provided.
Return type: out(numpy.ndarray)
>>> a = numpy.array( ... [[ True, True, False, False, False, False, False], ... [False, False, False, False, False, False, False], ... [False, False, False, False, False, False, False], ... [False, False, False, False, False, False, False], ... [False, False, False, False, True, False, False], ... [False, False, False, False, False, False, False], ... [False, False, False, False, False, False, False]], dtype=bool ... ) >>> b = numpy.zeros_like(a)
>>> binary_dilation(a, numpy.ones(a.ndim*(3,), dtype=bool)) array([[ True, True, True, False, False, False, False], [ True, True, True, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, False, False, False, False]], dtype=bool)
>>> binary_dilation(a, numpy.ones(a.ndim*(3,), dtype=bool), out=b) array([[ True, True, True, False, False, False, False], [ True, True, True, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, False, False, False, False]], dtype=bool) >>> b array([[ True, True, True, False, False, False, False], [ True, True, True, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, False, False, False, False]], dtype=bool)
>>> binary_dilation(a, numpy.ones(a.ndim*(3,), dtype=bool), out=a) array([[ True, True, True, False, False, False, False], [ True, True, True, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, False, False, False, False]], dtype=bool) >>> a array([[ True, True, True, False, False, False, False], [ True, True, True, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, True, True, True, False], [False, False, False, False, False, False, False]], dtype=bool)
-
nanshe.imp.filters.masks.
binary_erosion
(*args, **kwargs)[source]¶ Performs simple binary erosion on a bool array of arbitrary dimension.
Parameters: - input_array (numpy.ndarray) – the bool array to perform erosion on.
- footprint (numpy.ndarray) – the footprint to use for the kernel.
- out (numpy.ndarray) – a place to store the result if provided. (optional)
Returns: - Same as out if out was
provided.
Return type: out(numpy.ndarray)
>>> a = numpy.array( ... [[ True, True, True, False, False, False, True], ... [ True, True, True, False, False, True, True], ... [False, False, False, False, False, False, False], ... [False, False, False, True, True, True, False], ... [False, True, False, True, True, True, False], ... [False, True, False, True, True, True, False], ... [False, False, False, False, False, False, True]], dtype=bool ... ) >>> b = numpy.zeros_like(a)
>>> binary_erosion(a, numpy.ones(a.ndim*(3,), dtype=bool)) array([[ True, True, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, True, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]], dtype=bool)
>>> binary_erosion(a, numpy.ones(a.ndim*(3,), dtype=bool), out=b) array([[ True, True, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, True, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]], dtype=bool) >>> b array([[ True, True, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, True, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]], dtype=bool)
>>> binary_erosion(a, numpy.ones(a.ndim*(3,), dtype=bool), out=a) array([[ True, True, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, True, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]], dtype=bool) >>> a array([[ True, True, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, True, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]], dtype=bool)