HitMissTransform[image,ker]
gives the hit-or-miss transform of image with respect to the composite structuring element ker.
HitMissTransform[image,{ker1,ker2,…}]
gives the union of the hit-or-miss transforms for all the structuring elements keri.
HitMissTransform[image,{ker1,ker2,…},t]
treats values above t as foreground.
HitMissTransform
HitMissTransform[image,ker]
gives the hit-or-miss transform of image with respect to the composite structuring element ker.
HitMissTransform[image,{ker1,ker2,…}]
gives the union of the hit-or-miss transforms for all the structuring elements keri.
HitMissTransform[image,{ker1,ker2,…},t]
treats values above t as foreground.
Details and Options
- HitMissTransform is an image morphology operation that is commonly used to detect positions where a specific pattern such as a corner or an endpoint occurs in the image.
- HitMissTransform works with arbitrary 2D and 3D images.
- The composite structuring element ker is a matrix containing
(foreground),
(background), and
(don't care) elements. - The structuring element is automatically padded with zeros to have odd dimensions.
- HitMissTransform takes a Padding option. The default setting is Padding->1.
Examples
open all close allBasic Examples (5)
Find all foreground pixels that are below a background pixel:
HitMissTransform[[image], (| |
| -- |
| -1 |
| 1 |)]Find runs of three foreground pixels below three background pixels:
HitMissTransform[[image], (| | | |
| -- | -- | -- |
| -1 | -1 | -1 |
| 1 | 1 | 1 |), Padding -> 0]HitMissTransform[[image], (| | |
| -- | -- |
| 1 | -1 |
| -1 | -1 |)]Find all corners by specifying four structuring elements:
HitMissTransform[[image], {(| | |
| -- | -- |
| 1 | -1 |
| -1 | -1 |), (| | |
| -- | -- |
| -1 | 1 |
| -1 | -1 |), (| | |
| -- | -- |
| -1 | -1 |
| 1 | -1 |), (| | |
| -- | -- |
| -1 | -1 |
| -1 | 1 |)}]HitMissTransform[[image], DiskMatrix[9]]Scope (9)
Data (4)
Find background pixels on top of foreground pixels:
HitMissTransform[[image], (| |
| -- |
| -1 |
| 1 |)]On a grayscale image, all values above 0 are treated as foreground:
HitMissTransform[[image], (| |
| -- |
| -1 |
| 1 |)]Specify a different foreground/background threshold:
HitMissTransform[[image], (| |
| -- |
| -1 |
| 1 |), 0.5]On a color image, all values above 0 are treated as foreground:
HitMissTransform[[image], (| |
| -- |
| -1 |
| 1 |)]Specify a different foreground/background threshold:
HitMissTransform[[image], (| |
| -- |
| -1 |
| 1 |), .5]Hit-or-miss transformation of a 3D image:
HitMissTransform[\!\(\*Graphics3DBox[«8»]\), DiskMatrix[{8, 8, 8}]]Kernel (5)
Find all foreground locations that fit a uniform
structuring element:
HitMissTransform[[image], (| | | |
| - | - | - |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |)]Find all background locations that fit a uniform
structuring element:
HitMissTransform[[image], (| | | |
| -- | -- | -- |
| -1 | -1 | -1 |
| -1 | -1 | -1 |
| -1 | -1 | -1 |)]Find a specific pattern of foreground and background pixels:
HitMissTransform[[image], (| | | | | |
| -- | -- | - | - | -- |
| -1 | -1 | 1 | 1 | -1 |
| 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 |)]Find corners using four structuring elements:
HitMissTransform[[image], {(| | | |
| - | -- | -- |
| 0 | 1 | 0 |
| 1 | 1 | -1 |
| 0 | -1 | -1 |), (| | | |
| -- | -- | - |
| -1 | -1 | 0 |
| -1 | 1 | 1 |
| 0 | 1 | 0 |), (| | | |
| -- | -- | - |
| 0 | 1 | 0 |
| -1 | 1 | 1 |
| -1 | -1 | 0 |), (| | | |
| - | -- | -- |
| 0 | -1 | -1 |
| 1 | 1 | -1 |
| 0 | 1 | 0 |)}]Use a 3D composite structuring element that exactly matches the shape and size of a foreground object:
ball = DiskMatrix[{7, 7, 7}] /. 0 -> -1;Dilation[HitMissTransform[[image], ball], 2]Related Guides
Text
Wolfram Research (2008), HitMissTransform, Wolfram Language function, https://reference.wolfram.com/language/ref/HitMissTransform.html (updated 2012).
CMS
Wolfram Language. 2008. "HitMissTransform." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/HitMissTransform.html.
APA
Wolfram Language. (2008). HitMissTransform. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HitMissTransform.html
BibTeX
@misc{reference.wolfram_2026_hitmisstransform, author="Wolfram Research", title="{HitMissTransform}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/HitMissTransform.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_hitmisstransform, organization={Wolfram Research}, title={HitMissTransform}, year={2012}, url={https://reference.wolfram.com/language/ref/HitMissTransform.html}, note=[Accessed: 15-June-2026]}