bundles / scipy latest / scipy / ndimage / _morphology / binary_hit_or_miss
function
scipy.ndimage._morphology:binary_hit_or_miss
Signature
def binary_hit_or_miss ( input , structure1 = None , structure2 = None , output = None , origin1 = 0 , origin2 = None , * , axes = None ) Summary
Multidimensional binary hit-or-miss transform.
Extended Summary
The hit-or-miss transform finds the locations of a given pattern inside the input image.
Parameters
input: array_like (cast to booleans)Binary image where a pattern is to be detected.
structure1: array_like (cast to booleans), optionalPart of the structuring element to be fitted to the foreground (non-zero elements) of
input. If no value is provided, a structure of square connectivity 1 is chosen.structure2: array_like (cast to booleans), optionalSecond part of the structuring element that has to miss completely the foreground. If no value is provided, the complementary of
structure1is taken.output: ndarray, optionalArray of the same shape as input, into which the output is placed. By default, a new array is created.
origin1: int or tuple of ints, optionalPlacement of the first part of the structuring element
structure1, by default 0 for a centered structure.origin2: int or tuple of ints, optionalPlacement of the second part of the structuring element
structure2, by default 0 for a centered structure. If a value is provided fororigin1and not fororigin2, thenorigin2is set toorigin1.axes: tuple of int or NoneThe axes over which to apply the filter. If None,
inputis filtered along all axes. Iforigin1ororigin2tuples are provided, their length must match the number of axes.
Returns
binary_hit_or_miss: ndarrayHit-or-miss transform of
inputwith the given structuring element (structure1,structure2).
Notes
Array API Standard Support
binary_hit_or_miss has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy import ndimage import numpy as np a = np.zeros((7,7), dtype=int) a[1, 1] = 1; a[2:4, 2:4] = 1; a[4:6, 4:6] = 1 a structure1 = np.array([[1, 0, 0], [0, 1, 1], [0, 1, 1]]) structure1 ndimage.binary_hit_or_miss(a, structure1=structure1).astype(int) ndimage.binary_hit_or_miss(a, structure1=structure1,\ origin1=1).astype(int)✓
See also
- binary_erosion
Aliases
-
scipy.ndimage.binary_hit_or_miss