Histogram equalization & CLAHE — computer vision in the browser
Histogram equalization spreads out a dull image’s tones to boost contrast; CLAHE does it adaptively per region so bright areas don’t blow out — a common computer-vision enhancement. This fetches a low-contrast photo and compares cv2.equalizeHist with cv2.createCLAHE. Run it live.
Example code (Python / OpenCV)
"""
Histogram equalization & CLAHE
Histogram equalization spreads out a dull image’s tones to boost contrast; CLAHE does it adaptively per region so bright areas don’t blow out — a common computer-vision enhancement. This fetches a low-contrast photo and compares cv2.equalizeHist with cv2.createCLAHE. Run it live.
"""
import cv2
import requests
import numpy as np
# A real photo, fetched live from the web — nothing is uploaded
url = "https://images.unsplash.com/photo-1506863530036-1efeddceb993?w=480&q=70"
# no-cache: always fetch a fresh copy so a stale browser-cache entry can't break decoding
resp = requests.get(url, headers={"Cache-Control": "no-cache"})
img = cv2.imdecode(np.frombuffer(resp.content, np.uint8), cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("original", gray)
# Global equalization vs CLAHE (adaptive, avoids over-brightening)
cv2.imshow("equalized", cv2.equalizeHist(gray))
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
cv2.imshow("CLAHE", clahe.apply(gray))