Change the arrangement.
Keep the counts equal. Watch the structure.
Boundary changes
The foreground still forms one connected region.
A severed bridge
A four-pixel cut separates the two regions.
Each mask misses 32 pixels and adds 32 elsewhere.
448 / 512=448 / 512
Large scores are rounded; these integer ratios match exactly.- Matched TP
- Added FP
- Missed FN
Numbered colors: regions. Amber hatching: missed pixels.
Move four missed pixels from the outer boundary into the narrow bridge. The two regions separate, while the overlap counts stay equal.
Inspect corresponding pixels: point or tap either diagram, or focus it and use the arrow keys. Escape clears the marker.
An overlap score counts agreement.
Let G be the reference foreground and P a proposed mask. A true positive is a pixel in both sets; a false positive belongs only to P; a false negative belongs only to G. Dice summarizes those counts in a single ratio.
Select a term to highlight its pixels in both diagrams above.
| Pixels | Mask A | Mask B |
|---|---|---|
| Matched TP | — | — |
| Added FP | — | — |
| Missed FN | — | — |
| Background agreement TN | — | — |
Why the counts force equal Dice
Each reference contains 256 foreground pixels. We remove k of them and add k background pixels. Every prediction therefore also has area 256, with TP = 256 − k and FP = FN = k. For both masks,
At k = 32: 448 / 512 = 0.875.
The equality is exact before rounding. Rearranging those errors leaves the ratio unchanged because their coordinates never enter the formula. Agreement on background pixels, TN, is also absent from Dice.
Then ask what connects.
A connected region is a group of foreground pixels joined by an edge-to-edge path. The bridge and island examples change the number of these regions. The cavity example keeps a single region but creates an enclosed background hole.
1A/2B
0A/0B
We use 4-neighbor foreground connectivity and complementary 8-neighbor background connectivity. A background region is a hole only if it cannot reach the image boundary, including by a diagonal step. The reference always has one foreground region and no holes.
These counts answer specific structural questions. Matching them would not prove that two masks have the same shape, boundary accuracy or network organization. Nor is a connected mask automatically better: the intended object and task determine which structures should be present.
Overlap and structure describe different properties of the same mask. A useful evaluation makes both visible.
A construction you can inspect.
Three recipes. Eight error budgets. No randomness. The same settings regenerate the same binary masks.
The download includes both masks, the reference, settings and integer counts as JSON.
Construction and measurement details
All masks occupy a 40-column by 24-row grid. Coordinates are zero-based, x increases rightward, and y increases downward. For the bridge recipe, two 10 × 12 blocks are joined by an 8 × 2 bridge. The severed version removes the central 2 × 2 portion of that bridge and allocates the remaining missed pixels to the outer boundary. Both masks add the same pixels below the blocks.
The island and cavity recipes use a 16 × 16 reference square. Boundary removals proceed from its top edge. Added pixels either extend the bottom edge or form a separate 8-column island. Cavity removals occupy an interior 8-column patch. The slider offers k = 8, 16, …, 64; each pair has exactly k missed and k added pixels.
The readable calculation source defines the full coordinate recipes. The JSON download contains every binary pixel, so the result can be checked without relying on that implementation. The formula is undefined when both masks are empty; this demonstration never generates that case.
Scope and references
This is an original synthetic teaching prototype, not a study, a trained segmentation model, or a proposed replacement metric. It makes no claims about the frequency or downstream impact of these configurations in real data. It covers binary 2D masks at one resolution.
- SciPy: Dice dissimilarity and its conversion to similarity. Reference for the count-based definition used here.
- scikit-image: Euler number and complementary connectivity conventions. Reference for the foreground/background neighborhood distinction.