
ImageMagick's connected-component labels depend on whether you request four-way or eight-way connectivity. Diagonally touching foreground pixels can remain separate under the four-neighbor rule and join under the eight-neighbor rule. Choose that topology before treating a region count as an object count.
Define what should count as connected
For a deliberately simple binary test, imagine two white squares touching only at one corner on black. This hypothetical arrangement isolates diagonal adjacency; it is not an executed ImageMagick example.
If the design treats that corner contact as one continuous object, test eight-way connectivity. If only shared horizontal or vertical neighbors should connect, test four-way connectivity. Neither choice recognizes the semantic objects in a photograph.
Request a label report
A proposed POSIX-shell comparison is:
magick marks.png -define connected-components:verbose=true -connected-components 4 labels-four.png
magick marks.png -define connected-components:verbose=true -connected-components 8 labels-eight.png
The commands have not been executed. The official component-labeling guide documents verbose output with label ID, bounding box, centroid, area and mean color. Confirm the installed ImageMagick 7 build and preserve the original input separately.
Keep the input and color-matching settings identical between runs. Changing -fuzz at the same time changes which colors can join, obscuring the connectivity comparison.
Identify the background in the report
A label is a connected pixel region, not automatically a foreground mark. The background can occupy a large component, and an enclosed region can appear as another label. Inspect the reported mean color, area and bounds before counting the entries that answer your actual question.
The GIMP selection guide chooses connected versus image-wide selection from a clicked color. This task creates a complete labeled-region inventory, including components unrelated to a single click.
Accept membership as well as count
For the corner-touching test, compare the labels assigned to both marks and their combined or separate statistics. A smaller report is not inherently better if the specification requires separate objects.
The Krita color-splitting guide addresses color-layer fragmentation instead. Here record the connectivity rule with the region report so another reader can explain why the same pixels produced a different set of components. No detector accuracy or completed segmentation is claimed.
Related tasks
- GIMP Fuzzy Select vs. Select by Color: Which One Captures Only the Background?
- How Should You Set Split Layer Fuzziness for Antialiased Artwork in Krita?
Sources and scope
- ImageMagick 7 option reference: connected-components: Four-way and eight-way connectivity produce different component membership; verbose output reports per-label bounding boxes, centroids, areas and mean colors.
- ImageMagick connected-component labeling: Per-label geometry statistics, background handling and component-membership controls.
Official ImageMagick 7 documentation was captured October 23, 2026. Examples and checks are proposed, not executed. Confirm the installed build, required delegates, actual file representation 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: Pignatta / Pixabay, Pixabay Content License. This is an illustrative source photograph, not an application screenshot or a generated test result.