← Ziding Zhang

A phone photo, re-shot through a fast lens: a depth map and some lens maths in your browser

Tap a photo to focus and pick a lens. A depth model guesses how far away each pixel is, thin-lens maths turns that into a blur size, and every pixel is redrawn as the lens's aperture shape. Street lights become cat's-eye bokeh. It works on your own photos without uploading them.

December 1, 2026 · Project · What is not yet established


A phone photo has nearly everything sharp because its lens is tiny. A camera with a big lens at f/1.4 blurs whatever is off the focus plane, and the blur grows with distance from it. If you know how far away each pixel is, you can compute that blur. A post by @1umsensor showed this with Apple’s Depth Pro and a lens simulation; this is my version, in the browser.

Left: a phone photo of a cappuccino on a café table, with the cup, saucer and table all fairly sharp. Right: the same pixels re-rendered as an 85 mm lens at f/1.4 focused on the biscuit: the far rim of the cup, the table and the window behind fall into smooth blur.
The phone photo (left) and the same pixels through the simulated 85 mm f/1.4, focused on the biscuit (right). Photo by Edward, Wikimedia Commons, CC0.
Try it Tap the photo to focus. Change the lens and the aperture and watch the blur follow the depth map.
…
Photo

Or use your own. It stays on your device: the depth model downloads once and runs in your browser.

Lens
Aperture
Where the camera stands
Nearest thing
Farthest thing
Highlight recovery
Show
Left: a phone photo of a narrow street at night under strings of Christmas lights, all sharp. Right: the same photo as an 85 mm f/1.4 focused on the nearest bollard: the light strings dissolve into round and lemon-shaped discs, the shops behind go soft, the bollard stays sharp.
Street lights, phone (left) and 85 mm f/1.4 focused on the nearest bollard (right). Toward the corners the discs are clipped into lemon shapes, as in real fast lenses. Photo by Andy Li, Wikimedia Commons, CC0.

How it works. A depth model estimates relative distance for every pixel. Two numbers, the nearest and farthest things in the photo, turn that into metres. The thin-lens formula gives each pixel’s blur circle from the focal length, the f-number and the focus distance. Then every pixel is redrawn as a small sprite in the shape of the lens’s opening at that spot in the frame: a polygon when stopped down, clipped into a lemon toward the corners, with a brighter rim behind the focus plane and a colour fringe. Near blur is drawn over far blur, not the other way round.

Same framing or same spot. A phone sees about as wide as a 26 mm lens. To frame the cup the same way with an 85 mm you’d step back about three times as far, which is the default. “Same spot” keeps the phone’s distances, as if the long lens were stuck at the phone’s position. It blurs far more.

What it can’t do. Where depth changes sharply (the rim of a cup, hair), the depth map is soft, so the blur leaks a little. A real lens also sees slightly around a foreground object, which no single photo contains. And the lenses are characters I tuned by eye, not measurements.

Your photo never leaves your device: the depth model (about 27 MB) downloads once and runs in your browser. It’s the same family of one-photo tricks as relighting a museum photograph: a model guesses the geometry, then ordinary optics does the rest.

Agent context: sources, method and working notes

Pipeline. Depth: Depth Anything V2 Small (paper, Apache-2.0), the ONNX build onnx-community/depth-anything-v2-small through Transformers.js 3.7.1: WebGPU fp16 where available, otherwise WASM 8-bit. The two sample depth maps were made with the same model (fp32, Node) and stored as 16-bit values packed into the red and green channels of a PNG at half resolution. The original post used Depth Pro, which gives metric depth; its weights are under a research licence and too large to ship to a browser, so I used the smaller Apache-licensed model and asked the reader for the scale instead.

Depth to metres. The model’s output is affine-invariant inverse depth, normalised here to d in [0, 1]. Metric inverse depth is D = 1/z_far + d (1/z_near − 1/z_far), with both distances set by sliders (defaults per sample; 0.6 m and 20 m for uploads).

Blur size. For focal length f, f-number N and focus distance z_f, the circle of confusion of a point at z is c = f² z_f / (N (z_f − f)) · |1/z_f − 1/z|. It is linear in inverse depth, which is why relative inverse depth is enough once scaled. The radius in pixels is c/2 divided by 36 mm (full-frame long edge) times the image’s long edge in pixels. “Same framing” assumes the phone is a 26 mm-equivalent and moves the camera back by (f/26 − 1) z_f, adding that to every distance.

Rendering. WebGL 2, one point sprite per pixel. Sprites are summed additively in 28 layers ordered by signed blur radius (far to near); each sprite’s weight is 1 / its aperture area, so a layer’s summed weight is its coverage. Each layer is normalised and composited over the layers behind it; the final image is divided by total coverage, which fills the holes left behind foreground objects with nearby colour instead of black. Before blurring, sRGB is linearised and near-white pixels are multiplied (up to 1 + 10 × the highlight slider) so clipped lights carry enough energy to form bright discs; a soft shoulder compresses them again afterwards. Previews render at 720 px on the long edge while dragging, 1280 px once still, 2400 px for “Save PNG”. On an Apple-silicon laptop a 1280 px render takes 0.1 to 0.7 s depending on how large the blur is. Without the EXT_float_blend extension (some phones), the maximum blur radius drops to 24 px to stay within half-float precision.

Lens characters. All invented: 35 mm f/1.4 (9 blades, strong cat’s-eye, bright rims), 50 mm f/1.4 (8 straight blades, double-Gauss-like rims), 85 mm f/1.4 (11 rounded blades, mild rims), 135 mm f/2 (9 rounded blades, soft rims). Blades round off when wide open and become polygons as you stop down; cat’s-eye clipping shrinks as you stop down, as it does in real lenses. Colour fringing makes the green image slightly larger behind focus and the red and blue images larger in front.

Not checked. No comparison against a real camera photo of the same scene; no measured lens data; edges not refined (a guided filter on the depth map would help); the samples were chosen to look good.

Try or break it. The renderer is one file, lens.js, with no build step. Useful next steps: photograph one scene with a phone and with a real 50 mm at f/1.4 and compare the blur sizes; swap in a metric depth model and drop the sliders; add measured lens data (blade shape, aberrations) for one real lens.

Have an answer, a counterexample, or a story? See Talk to me for open questions and live trials.

Credits: Ziding Zhang. Renderer, page and write-up by Claude agents under my direction. Idea from a post by @1umsensor, who did this with Apple's Depth Pro. Depth: Depth Anything V2 Small (Apache-2.0) via Transformers.js. Photos: Edward and Andy Li on Wikimedia Commons, both CC0.