RemapBarrelDistortion
Add or remove real lens distortion — the a/b/c/d of barrel and pincushion
- REMAP
Barrel distortion is what makes straight lines bow outward like the sides of a barrel - it's the signature of wide-angle and fisheye lenses. Pincushion distortion bows them inward, and mustache distortion does a weird mix of both. RemapBarrelDistortion lets you add or correct all three using the standard polynomial model from lens optics, the same coefficients you'd see in calibration software. If you've got a photo shot on a wide lens and want the buildings to stand straight, or you want to fake a fisheye look from a normal shot, this is the node.
It's a REMAP generator, so it doesn't distort anything by itself: wire its output into the Remap node, which applies it to your source image. RemapBarrelDistortion → Remap → image.
How it works
The mechanism is a textbook lens model. For each pixel it computes the radius from the image center (normalized), then remaps that radius through a cubic polynomial: r' = (a·r³ + b·r² + c·r + d) · r. The coefficients a, b, c (and optionally d) shape the curve: positive a gives barrel, negative gives pincushion, and mixing signs gives mustache. When d isn't supplied, it's derived so the center stays put (d = 1 - (a+b+c)).
The use_inverse_variant toggle switches between two formulas for computing the new radius - the plain polynomial, or a reciprocal variant used when you want to correct (undo) distortion rather than create it. The author's source comment is upfront that it's "not a mathematical inverse" of the forward function - it's a different formula that behaves like the reverse, which is why the pack also ships RemapReverseBarrelDistortion for the true undo path.
The inputs
a,b,c(FLOAT, −10 to 10, fine-grained steps) - the polynomial coefficients. This is where the actual lens character lives.d(FLOAT, optional) - the fourth coefficient; leave unconnected to let the node derive it.use_inverse_variant(BOOLEAN, default on) - formula switch.
Output: REMAP.
Where people get burned
The coefficient values are tiny - the default step is 1e-5, and you'll typically be working with numbers around 0.001 to 0.01. Big values blow the image apart instantly. The other trap is sign confusion: same coefficients, different sign, and you've gone from barrel to pincushion. Set a small and positive first (say 0.002), preview through the Remap node, and adjust from there. For actually correcting a real photo, you usually want use_inverse_variant on and the same small coefficients - and then check the reverse node, because on hard cases the two genuinely differ.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
restart, or search comfyui_bmad_nodes in ComfyUI Manager. OpenCV covers it; no model downloads.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| a | FLOAT | 0.0000-10–10 | — |
| b | FLOAT | 0.0000-10–10 | — |
| c | FLOAT | 0.0000-10–10 | — |
| use_inverse_variant | BOOLEAN | true | — |
| dopt | FLOAT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| REMAP | REMAP | — |