from PIL import Image

img = Image.open("captures/20260914_003238_869_AFTER_CLICK_SHIFTED_NODE.png")
crop = img.crop((450, 650, 750, 850))
crop.save("captures/nodes_crop.png")
print("Saved nodes_crop.png")

# Scan green pixels in that crop
green_pts = []
for x in range(450, 750):
    for y in range(650, 850):
        r, g, b = img.getpixel((x, y))[:3]
        # green glow has g > 150 and g > r * 1.3 and g > b * 1.3
        if g > 120 and g > r * 1.2 and g > b * 1.2:
            green_pts.append((x, y))

print(f"Found {len(green_pts)} green pixels")
if green_pts:
    # Cluster them
    clusters = []
    # simple clustering
    for pt in green_pts:
        found = False
        for c in clusters:
            # check distance to first point
            if abs(pt[0] - c[0][0]) < 30 and abs(pt[1] - c[0][1]) < 30:
                c.append(pt)
                found = True
                break
        if not found:
            clusters.append([pt])
    
    print(f"Found {len(clusters)} clusters:")
    for idx, c in enumerate(clusters):
        cx = sum(p[0] for p in c) // len(c)
        cy = sum(p[1] for p in c) // len(c)
        print(f"Cluster {idx} (size {len(c)}): center = ({cx}, {cy})")
