Fix false edge-whitening on die-cut/mixed-material cards (e.g. SPx clear acetate window)

The pooled baseline that scores edge whitening was global across all four
edges, so a card that's normal printed border on three sides and clear
acetate on the fourth had the three normal edges anchor a baseline that made
the clear side read as extreme whitening -- correctly detecting a real pixel
difference, just the wrong one. Now excludes an edge from both the pool and
its own scoring when its median brightness/saturation reads as a
fundamentally different material, and surfaces why in the prompt instead of
silently dropping it.
This commit is contained in:
Barely Removable 2026-08-22 11:09:44 -07:00
parent f464faca43
commit 552f862f4c
2 changed files with 84 additions and 8 deletions

View file

@ -676,11 +676,29 @@ def grade_card(images, api_key=None, model=None, effort=None, zoom_details=True)
measured.get("reason", "of its finish")))
elif measured:
rows = []
note_rows = []
edge_notes = measured.get("edge_notes") or {}
for side in ("top", "right", "bottom", "left"):
data = (measured.get("edges") or {}).get(side)
if data:
rows.append(" {} edge: {:.1f}% of its length".format(
side, data["percent"]))
elif side in edge_notes:
note_rows.append(" {} edge: NOT MEASURED — {}".format(
side, edge_notes[side]))
if note_rows:
prompt_parts.append(
"\n".join(note_rows) + "\n"
"For any edge noted above as not measured due to a different "
"material, judge it from its strip image alone, on its own "
"terms as whatever that material is — do not read its "
"brightness or lack of saturation as whitening just because "
"it looks nothing like the card's other edges. Look instead "
"for actual physical damage on that material: a crack or "
"chip in a clear acetate window, foil peeling or flaking, a "
"scuff that catches light differently than the surrounding "
"area — the same kind of judgement as any other edge, just "
"without a number to anchor it.")
if rows:
prompt_parts.append(
"MEASURED EDGE WHITENING — computed directly from the pixels, "