Lens Distortion
Barrel, pincushion, mustache — or your actual lens's coefficients
- image
- mask
- image
Wide-angle lenses bow straight lines outward (barrel distortion); telephotos bow them inward (pincushion). Get a lens with both and you get the "mustache" curve. It's a flaw - but it's a familiar flaw, and generated images that have zero geometric distortion are part of that sterile "too perfect" look. Lens Distortion lets you add real distortion to sell the shot, or remove it from a source that already has it.
It's part of ComfyUI-Darkroom's Lens & Optics group, and it's the geometric sibling of Chromatic Aberration: same philosophy, same 103-choice lens dropdown, different axis of the same optical problem. The two are often used together - a "real lens" look is distortion plus fringing plus a little vignette.
How it works
The node implements the Brown-Conrady radial model: a point's distance from the center gets remapped by the polynomial r' = r * (1 + k1*r² + k2*r⁴). Negative k1 = barrel (edges bow out), positive k1 = pincushion (edges bow in), and a k2 with the opposite sign produces mustache distortion - the weird one where the middle bows one way and the corners the other. Real lens profiles in the dropdown carry their measured k1/k2 values; "Custom" hands you the two coefficients raw. The strength slider is a multiplier on the whole thing, and here's the clever bit: negative strength inverts the distortion, which turns "add barrel" into "correct barrel."
The inputs that matter
- lens - 103 choices: Custom plus 102 real lens profiles (Canon EF primes and zooms, measured, not guessed).
- strength - multiplier, −2 to +2. Negative corrects; positive adds.
- k1 - primary radial coefficient, −1 to +1. Negative = barrel, positive = pincushion.
- k2 - secondary coefficient, ±0.5. Opposite sign to k1 = mustache.
Output is image - the frame gets warped, the canvas doesn't, so corners may crop slightly at high strengths.
Install and gotchas
cd ComfyUI/custom_nodes
git clone https://github.com/jeremieLouvaert/ComfyUI-Darkroom
pip install -r ComfyUI-Darkroom/requirements.txt
Or search "Darkroom" in ComfyUI Manager and restart. It's under AKURATE/Darkroom/Lens.
The trap is obvious in hindsight: distortion is spatial, so it's banned from the LUT bake chain - apply it after Extract. And when you pick a real lens profile and see no change, that's usually correct - modern EF primes are well-corrected, so their coefficients are tiny. If you want visible character, pick a vintage or wide zoom profile, or go Custom with k1 around −0.15 to −0.3. Barrel distortion in particular reads as "shot on a real wide-angle" to most people, and at strength 0.3–0.5 it's one of the cheapest realism hacks in the pack.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| lens | COMBO | Custom | Select a real lens or 'Custom' for manual distortion control |
| strength | FLOAT | 1.0-2–2 | Multiplier. Negative inverts (correct distortion instead of adding it) |
| k1opt | FLOAT | 0.00-1–1 | Primary radial coefficient. Negative=barrel, Positive=pincushion |
| k2opt | FLOAT | 0.00-0.5–0.5 | Secondary radial coefficient. Creates mustache distortion when opposite sign to k1 |
| maskopt | MASK | Where the distortion applies, 0 to 1. Scales the warp itself, so partial values do not ghost. Feather the mask edge by about twice the local displacement (tens to hundreds of px at strong settings) or a smear band forms along the edge. Strong distortion near the frame border can pull black in from outside the frame, masked or not. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |