Image gradients (Sobel & Laplacian) — computer vision in the browser
Gradients measure how fast brightness changes — the raw signal edge detectors build on. Sobel finds horizontal and vertical change; the Laplacian finds it in all directions at once. This fetches a real photo and shows all three (cv2.Sobel, cv2.Laplacian). Run it live.
Example code (Python / OpenCV)
"""
Image gradients (Sobel & Laplacian)
Gradients measure how fast brightness changes — the raw signal edge detectors build on. Sobel finds horizontal and vertical change; the Laplacian finds it in all directions at once. This fetches a real photo and shows all three (cv2.Sobel, cv2.Laplacian). 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-1543872084-c7bd3822856f?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)
# Gradients find where brightness changes — the basis of edges
cv2.imshow("sobel x", cv2.convertScaleAbs(cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=3)))
cv2.imshow("sobel y", cv2.convertScaleAbs(cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=3)))
cv2.imshow("laplacian", cv2.convertScaleAbs(cv2.Laplacian(gray, cv2.CV_64F)))