bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / morphology / gray / black_tophat
function
skimage.morphology.gray:black_tophat
source: /dev/scikit-image/src/skimage/morphology/gray.py :578
Signature
def black_tophat ( image , footprint = None , out = None , * , mode = reflect , cval = 0.0 ) Summary
Return black top hat of an image.
Extended Summary
The black top hat of an image is defined as its morphological closing minus the original image. This operation returns the dark spots of the image that are smaller than the footprint. Note that dark spots in the original image are bright spots after the black top hat.
Parameters
image: ndarrayImage array.
footprint: ndarray or tuple, optionalThe neighborhood expressed as a 2-D array of 1's and 0's. If None, use a cross-shaped footprint (connectivity=1). The footprint can also be provided as a sequence of smaller footprints as described in the notes below.
out: ndarray, optionalThe array to store the result of the morphology. If None is passed, a new array will be allocated.
mode: str, optionalThe
modeparameter determines how the array borders are handled. Valid modes are: 'reflect', 'constant', 'nearest', 'mirror', 'wrap', 'max', 'min', or 'ignore'. See skimage.morphology.closing. Default is 'reflect'.cval: scalar, optionalValue to fill past edges of input if
modeis 'constant'. Default is 0.0.
Returns
out: array, same shape and type as `image`The result of the morphological black top hat.
Notes
The footprint can also be a provided as a sequence of 2-tuples where the first element of each 2-tuple is a footprint ndarray and the second element is an integer describing the number of times it should be iterated. For example footprint=[(np.ones((9, 1)), 1), (np.ones((1, 9)), 1)] would apply a 9x1 footprint followed by a 1x9 footprint resulting in a net effect that is the same as footprint=np.ones((9, 9)), but with lower computational cost. Most of the builtin footprints such as skimage.morphology.disk provide an option to automatically generate a footprint sequence of this type.
Examples
import numpy as np from skimage.morphology import footprint_rectangle dark_on_gray = np.array([[7, 6, 6, 6, 7], [6, 5, 4, 5, 6], [6, 4, 0, 4, 6], [6, 5, 4, 5, 6], [7, 6, 6, 6, 7]], dtype=np.uint8) black_tophat(dark_on_gray, footprint_rectangle((3, 3)))✓
See also
Aliases
-
skimage.morphology.black_tophat