In
mathematical morphology, hit-or-miss transform is an operation that detects a given configuration (or pattern) in a
binary image
A binary image is one that consists of pixels that can have one of exactly two colors, usually black and white. Binary images are also called ''bi-level'' or ''two-level'', Pixelart made of two colours is often referred to as ''1-Bit'' or ''1b ...
, using the morphological
erosion
Erosion is the action of surface processes (such as water flow or wind) that removes soil, rock, or dissolved material from one location on the Earth's crust, and then transports it to another location where it is deposited. Erosion is di ...
operator and a pair of
disjoint structuring element In mathematical morphology, a structuring element is a shape, used to probe or interact with a given image, with the purpose of drawing conclusions on how this shape fits or misses the shapes in the image. It is typically used in morphological oper ...
s. The result of the hit-or-miss transform is the set of positions where the first
structuring element In mathematical morphology, a structuring element is a shape, used to probe or interact with a given image, with the purpose of drawing conclusions on how this shape fits or misses the shapes in the image. It is typically used in morphological oper ...
fits in the foreground of the input image, and the second structuring element misses it completely.
Mathematical definition
In binary morphology, an image is viewed as a
subset
In mathematics, set ''A'' is a subset of a set ''B'' if all elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they are unequal, then ''A'' is a proper subset o ...
of a
Euclidean space
Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are Euclidean sp ...
or the integer grid
, for some dimension ''d''. Let us denote this space or grid by ''E''.
A structuring element is a simple, pre-defined shape, represented as a binary image, used to probe another binary image, in morphological operations such as
erosion
Erosion is the action of surface processes (such as water flow or wind) that removes soil, rock, or dissolved material from one location on the Earth's crust, and then transports it to another location where it is deposited. Erosion is di ...
,
dilation,
opening, and
closing.
Let
and
be two structuring elements satisfying
. The pair (''C'',''D'') is sometimes called a ''composite structuring element''. The hit-or-miss transform of a given image ''A'' by ''B''=(''C'',''D'') is given by:
::
,
where
is the
set complement of ''A''.
That is, a point ''x'' in ''E'' belongs to the hit-or-miss transform output if ''C'' translated to ''x'' fits in ''A'', and ''D'' translated to ''x'' misses ''A'' (fits the background of ''A'').
Some applications
Thinning

Let
, and consider the eight composite structuring elements, composed of:
:
and
,
:
and
and the three rotations of each by 90°, 180°, and 270°. The corresponding composite structuring elements are denoted
.
For any ''i'' between 1 and 8, and any binary image ''X'', define
::
where
denotes the
set-theoretical difference.
The thinning of an image ''A'' is obtained by cyclically iterating until convergence:
:
Other applications
*
Pattern detection. By definition, the hit-or-miss transform indicates the positions where a certain pattern (characterized by the composite structuring element ''B'') occurs in the input image.
*
Pruning. The hit-or-miss transform can be used to identify the end-points of a line to allow this line to be shrunk from each end to remove unwanted branches.
* Computing the
Euler number.
Bibliography
* ''An Introduction to Morphological Image Processing'' by Edward R. Dougherty, {{ISBN, 0-8194-0845-X (1992)
Mathematical morphology
Digital geometry