Rajdhani font (OFL), chamfered/glitch drawing kit, Docker list every 5 s and process ranking over 3 s windows so the 1 s refresh stays cheap and calm. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
18 lines
707 B
Python
18 lines
707 B
Python
import numpy as np
|
|
from PIL import Image
|
|
|
|
|
|
def count_colour(img: Image.Image, colour, box=None) -> int:
|
|
"""Number of pixels of `colour` in `img` (optionally only inside `box`)."""
|
|
if box is not None:
|
|
img = img.crop(box)
|
|
return int((np.asarray(img.convert("RGB")) == np.array(colour)).all(axis=2).sum())
|
|
|
|
|
|
def count_near(img: Image.Image, colour, tolerance: int = 70, box=None) -> int:
|
|
"""Pixels within `tolerance` (per channel) of `colour`: for anti-aliased text, which is never exactly pure."""
|
|
if box is not None:
|
|
img = img.crop(box)
|
|
diff = np.abs(np.asarray(img.convert("RGB")).astype(int) - np.array(colour))
|
|
return int((diff.max(axis=2) <= tolerance).sum())
|