Bilateral filter (edge-preserving) — computer vision in the browser
The bilateral filter smooths flat regions but preserves edges — unlike a plain blur — by weighting neighbours on both distance and colour. It’s behind skin-smoothing and cartoon looks in computer vision. This fetches a real photo and applies cv2.bilateralFilter. Run it live and raise the sigmas for a stronger effect.
Example code (Python / OpenCV)
"""
Bilateral filter (edge-preserving)
The bilateral filter smooths flat regions but preserves edges — unlike a plain blur — by weighting neighbours on both distance and colour. It’s behind skin-smoothing and cartoon looks in computer vision. This fetches a real photo and applies cv2.bilateralFilter. Run it live and raise the sigmas for a stronger effect.
"""
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-1500648767791-00dcc994a43e?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)
cv2.imshow("original", img)
# Bilateral smooths flat areas but KEEPS edges (a soft, cartoon-ish look)
smooth = cv2.bilateralFilter(img, 9, 75, 75) # diameter, sigmaColor, sigmaSpace
cv2.imshow("bilateral", smooth)