
Zero and an ignored cell are different constraints in ImageMagick hit-and-miss morphology. A one requires foreground; zero requires background; an undefined cell means its value does not matter. Replacing every dash with zero can therefore prevent a pattern from matching pixels it was meant to accept.
Write the pattern's requirements
Use a binary input and identify the local arrangement you want to detect. Mark which neighboring positions must be foreground, which must be background and which are irrelevant.
The official Hit-And-Miss examples describe matching this configuration around the kernel origin. This is a local pattern query, not automatic recognition of an object or cleanup of every similar-looking mark.
Preserve ignored cells in the kernel
The documentation illustrates the difference with a three-position pattern:
magick binary-shape.png -morphology HitAndMiss '3x1:1,-,0' matches.png
This proposed POSIX-shell example has not been executed. Confirm the installed ImageMagick 7 method naming and kernel behavior. Here the middle position is deliberately unconstrained; changing it to zero requires that position to be background instead.
The source also accepts NaN for an ignored cell. Keep the literal undefined notation in the kernel rather than replacing it with an ordinary numeric zero during spreadsheet or code generation.
Inspect the origin's own requirement
A kernel can require foreground or background at its origin, or leave that location unconstrained. That choice changes which matched positions are reported even when the surrounding neighborhood looks similar.
Use a tiny diagnostic input containing an intended match, a near match with the wrong required background and a case that differs only at an ignored position. Write the expected inclusion rule before looking at the result. These are proposed cases, not measured match counts.
Read the output as match locations
A match map identifies locations satisfying the supplied neighborhood. It does not preserve the whole original shape or certify the meaning of the detected corner or junction.
The connected-selection guide expands from a clicked region, while hit-and-miss tests a declared local configuration. The trim-basis guide removes outer padding, rather than finding internal patterns.
Retain the binary input, pattern matrix and origin with the result. Accept only when both intended matches and explicit nonmatches follow the declared constraints. No completed pattern-detection test or semantic recognition accuracy is claimed.
Related tasks
- GIMP Fuzzy Select vs. Select by Color: Which One Captures Only the Background?
- Photoshop Trim: Remove Transparent Padding or a Solid Edge Color?
Sources and scope
- ImageMagick morphology examples: hitandmiss: HitAndMiss tests foreground/background neighborhoods at the origin; NaN or a dash expresses ignored locations while zero is a required background value.
- ImageMagick 7 morphology operator: Current command-line reference links to the official morphology examples; confirm installed methods and kernels.
The official ImageMagick morphology usage page was captured with HTTP 200 on October 23, 2026. It includes historical examples and explicit legacy version notes. Commands, calculations and acceptance exercises here are proposed, not executed; verify the installed ImageMagick 7 methods, kernel behavior, quantum precision and shell syntax.
Prepared by Imagild Editorial, the company editorial team responsible for these guides. AI assisted research and drafting. This is documentation-based guidance with proposed examples, not a claim of hands-on testing or an independent product review. Report a correction.
Cover: Mariya Eskina / Pexels, Pexels License. This is an illustrative source photograph, not an application screenshot or a generated test result.