Today I learned
How do I measure whether a screen overlay is washing out my game's colours?
· updated #Game development
"The picture looks muddy" is hard to act on. Put a number on it: screenshot the same frame with the overlay on and off and compare the Hasler–Süsstrunk colourfulness of the area you suspect.
import numpy as np
from PIL import Image
def colourfulness(path, edge=0.15):
img = np.asarray(Image.open(path).convert("RGB"), dtype=float)
h, w, _ = img.shape
m = np.zeros((h, w), bool) # the band along the screen edges
m[:int(h*edge)] = m[-int(h*edge):] = True
m[:, :int(w*edge)] = m[:, -int(w*edge):] = True
r, g, b = (img[..., i][m] for i in range(3))
rg, yb = r - g, 0.5 * (r + g) - b
return np.hypot(rg.std(), yb.std()) + 0.3 * np.hypot(rg.mean(), yb.mean())
The paper's scale: 15 is slightly colourful, 33 moderately, 59 quite.
Hit this on a painted 2D game whose seasonal weather layer had a soft colour frame along the screen edges. The white winter frame at alpha 0.3 dropped edge colourfulness from 65 to 47; the particles on top (snow, rain, leaves) changed nothing. I removed the frame, kept the particles, and the edges now score the same with weather on or off.
Source: Hasler & Süsstrunk, Measuring Colourfulness in Natural Images