ValEye · counting engine

What the counter fixed, and what still beats it

Every number here is measured against exact ground truth. The clusters that used to collapse now count correctly; the cases that remain turned out not to be clustering problems at all.

Photo corpus
239/253+1
Adversarial
35/48+14
Phantoms
170−91%
Overlaps
71−64%

Clusters that used to break it

Rafts collapsed to a single pill; textured boards produced hundreds of phantoms.

Hex raft, dark board

resolved
Hex raft, dark board: counter outlines over the photo
Current output — each outline is one counted pill.
Was
1
off by 18
Now
19
exact
Actual
19
ground truth

Hex raft, wood board

resolved
Hex raft, wood board: counter outlines over the photo
Current output — each outline is one counted pill.
Was
1
off by 18
Now
19
exact
Actual
19
ground truth

37-pill raft, dark

resolved
37-pill raft, dark: counter outlines over the photo
Current output — each outline is one counted pill.
Was
1
off by 36
Now
37
exact
Actual
37
ground truth

Crossed chains, noise

resolved
Crossed chains, noise: counter outlines over the photo
Current output — each outline is one counted pill.
Was
261
off by 248
Now
13
exact
Actual
13
ground truth

120-pill dense board

improved only
120-pill dense board: counter outlines over the photo
Current output — each outline is one counted pill.
Was
41
off by 79
Now
142
off by 22
Actual
120
ground truth

Ring (hollow centre)

resolved
Ring (hollow centre): counter outlines over the photo
Current output — each outline is one counted pill.
Was
1
off by 11
Now
12
exact
Actual
12
ground truth

Shiny beads (real photo)

improved only
Shiny beads (real photo): counter outlines over the photo
Current output — each outline is one counted pill.
Was
49
off by 15
Now
35
off by 1
Actual
34
ground truth

The separation sweep

Real pills cut from four difficult photos — colour, gloss, engraving and shadow intact — laid in a grid whose spacing walks from 3.0× pill width down to 1.7×. Only the arrangement is synthetic. Bar height is the count error; 2.0× is just touching.

r-7ff7fd99matte white caplets on brown never breaks
3.0×9
2.5×9
2.2×9
2.0×9
1.9×9
1.8×9
1.7×9
s-eb90778fspecular beads (gloss varies by angle) breaks at 1.9×
3.0×9
2.5×9
2.2×9
2.0×9
1.9×10
1.8×10
1.7×9
r-f5d11815speckled caplets breaks at 3.0×
3.0×10
2.5×9
2.2×9
2.0×9
1.9×9
1.8×10
1.7×10
lined-bfdbfef9pale pills on ruled paper breaks at 2.2×
3.0×9
2.5×9
2.2×15
2.0×9
1.9×9
1.8×9
1.7×9

Proximity is not what breaks the counter

Matte caplets survive every spacing, including past contact. Speckled caplets fail at 3.0×, fully separated. Two of the four curves are non-monotonic — failing at 1.9× and passing at 1.7× — which no proximity explanation can produce. The remaining failures are properties of the pill surface and the board, wearing a clustering costume.

Still failing

14 of 253 photos miscount. 9 are off by exactly one pill.

PhotoCountedActualOff
synth2-cc-light-normal-n60-t25-s298.png4348-5
lined/lined-69204ff4.jpg2220+2
lined/lined-bfdbfef9.jpg1820-2
synth2-rc-wood-small-n12-t65-s229.png1012-2
lined/lined-503b3041.jpg1820-2
synth2-rc-light-small-n30-t65-s140.png2930-1
synth2-cc-kraft-normal-n20-t25-s301.png1920-1
shiny/s-0bfc44d8.jpg3334-1
synth2-cc-kraft-normal-n60-t25-s302.png5960-1
shiny/s-eb90778f.jpg3534+1
synth2-rc-wood-normal-n12-t0-s233.png1112-1
real/r-7ff7fd99.jpg1920-1
synth2-rc-kraft-small-n120-t35-s258.png119120-1
synth2-rc-wood-normal-n30-t35-s238.png3130+1

The dense board: a fix that works and cannot ship

A greedy overlap peel — drop the deepest-penetrating outline, re-measure, repeat — takes the 120-pill board from 142 to 124 with every real pill still found. A fixed threshold cannot do this, because real touching pills overlap as much as 24.68px. But scoped or unscoped it costs corpus images, and the two it breaks are dense synthetics whose pills are legitimately packed: by every measure available, a genuinely dense board and one full of invented outlines look identical.

The shiny beads: root cause found, fix unaffordable

Five pills are discarded by a rule that drops blobs below 70% of median brightness as surface rather than product. That assumes one medication means one colour — true for matte tablets. A glossy pill is a small mirror, so its brightness comes from the angle it lies at. The discarded blobs are 2773px and 2064px against a median pill of 1435. Exempting pill-sized blobs costs seven corpus images; adding a length test still costs three, because dark surface marks are frequently both pill-sized and pill-long.