bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / ndimage / _morphology / black_tophat
function
scipy.ndimage._morphology:black_tophat
source: build-install/usr/lib/python3.14/site-packages/scipy/ndimage/_morphology.py:1902
Signature
def black_tophat(input, size = None, footprint = None, structure = None, output = None, mode = reflect, cval = 0.0, origin = 0, *, axes = None)Summary
Multidimensional black tophat filter.
Parameters
input: array_likeInput.
size: tuple of ints, optionalShape of a flat and full structuring element used for the filter. Optional if
footprintorstructureis provided.footprint: array of ints, optionalPositions of non-infinite elements of a flat structuring element used for the black tophat filter.
structure: array of ints, optionalStructuring element used for the filter.
structuremay be a non-flat structuring element. Thestructurearray applies offsets to the pixels in a neighborhood (the offset is additive during dilation and subtractive during erosion)output: array, optionalAn array used for storing the output of the filter may be provided.
mode: {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optionalThe
modeparameter determines how the array borders are handled, wherecvalis the value when mode is equal to 'constant'. Default is 'reflect'cval: scalar, optionalValue to fill past edges of input if
modeis 'constant'. Default is 0.0.origin: scalar, optionalThe
originparameter controls the placement of the filter. Default 0axes: tuple of int or NoneThe axes over which to apply the filter. If None,
inputis filtered along all axes. If anorigintuple is provided, its length must match the number of axes.
Returns
black_tophat: ndarrayResult of the filter of
inputwithstructure.
Examples
Change dark peak to bright peak and subtract background.from scipy.ndimage import generate_binary_structure, black_tophat import numpy as np square = generate_binary_structure(rank=2, connectivity=3) 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]]) black_tophat(input=dark_on_gray, structure=square)✓
array([[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 5, 1, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 0, 0]])
See also
Aliases
scipy.ndimage.black_tophat