from PIL import Image

img = Image.open("captures/20260914_003238_869_AFTER_CLICK_SHIFTED_NODE.png")
w, h = img.size

# Look for green node glow: bright green (high green, lower red and blue)
# In the whole image (left half, x < 1650)
green_pixels = []
for y in range(100, 1300, 2):
    for x in range(50, 1650, 2):
        r, g, b = img.getpixel((x, y))[:3]
        if g > 150 and g > r + 40 and g > b + 40:
            green_pixels.append((x, y))

print(f"Total green pixels: {len(green_pixels)}")

# Cluster them
clusters = []
for pt in green_pixels:
    matched = False
    for c in clusters:
        if abs(pt[0] - c["cx"]) < 25 and abs(pt[1] - c["cy"]) < 25:
            c["pts"].append(pt)
            c["cx"] = sum(p[0] for p in c["pts"]) // len(c["pts"])
            c["cy"] = sum(p[1] for p in c["pts"]) // len(c["pts"])
            matched = True
            break
    if not matched:
        clusters.append({"cx": pt[0], "cy": pt[1], "pts": [pt]})

clusters.sort(key=lambda c: len(c["pts"]), reverse=True)
print(f"Top 10 green clusters:")
for i, c in enumerate(clusters[:10]):
    print(f"Cluster {i}: ({c['cx']}, {c['cy']}), size={len(c['pts'])}")
