diff options
Diffstat (limited to 'scripts/analyze-p72.py')
| -rw-r--r-- | scripts/analyze-p72.py | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/scripts/analyze-p72.py b/scripts/analyze-p72.py index a9171e0..bd179ca 100644 --- a/scripts/analyze-p72.py +++ b/scripts/analyze-p72.py @@ -105,18 +105,47 @@ def main(): if mean > 75.0: world_pngs.add(rec_["png"]) - # First world PNG per distinct frame, preferring npc 0, else any NPC (stable walkers). + # Candidate world PNGs per frame: npc 0 first (stable walker), then other NPCs. + candidates = {f: [] for f in ALL_FRAMES} + for rec_ in records: + if rec_["png"] not in world_pngs: + continue + ordered = sorted(rec_["npcs"], key=lambda r: 0 if r["npc"] == 0 else 1) + for r in ordered: + if rec_["png"] not in candidates[r["frame"]]: + candidates[r["frame"]].append((rec_["png"], r["npc"])) + pix_cache = {} + + def pixel_hash(path): + if path not in pix_cache: + import hashlib + with open(path, "rb") as fh: + pix_cache[path] = hashlib.sha256(np.asarray(Image.open(path).convert("RGB")).tobytes()).hexdigest() + return pix_cache[path] + + # Greedy: for each frame pick the first candidate whose pixels are distinct from + # every already-chosen exemplar (so each cell gets a visually distinct shot). exemplar = {} - for want_npc in (0, -1): - for rec_ in records: - if rec_["png"] not in world_pngs: + used_pngs = set() + used_hashes = set() + for f in ALL_FRAMES: + choice = None + for png, npc in candidates[f]: + if png in used_pngs: + continue + if pixel_hash(png) in used_hashes: continue - for r in rec_["npcs"]: - if r["frame"] in exemplar: - continue - if want_npc == 0 and r["npc"] != 0: - continue - exemplar[r["frame"]] = (rec_["png"], r["npc"]) + choice = (png, npc) + break + if choice is None: + for png, npc in candidates[f]: + if png not in used_pngs: + choice = (png, npc) + break + if choice is not None: + exemplar[f] = choice + used_pngs.add(choice[0]) + used_hashes.add(pixel_hash(choice[0])) lines.append( "walk frame exemplars: " + ", ".join(f"{k}={Path(v[0]).name}(npc{v[1]})" for k, v in sorted(exemplar.items())) |
