Nodes/ComfyUI-HakuImg/LenDistortion
ComfyUI Node

LenDistortion

Add barrel or pincushion warp to fake a real lens

By licyk·Created 2 years ago·Updated 12 months ago· 14
LenDistortion
  • image
  • image
lens_distortion_k10.00
lens_distortion_k20.00

Every real camera lens bends the image slightly - straight lines bow outward near a wide-angle lens (barrel distortion) or pinch inward with some telephoto and macro lenses (pincushion). Diffusion models render geometrically perfect scenes by default, which is one more quiet tell that separates a render from a photo. LenDistortion adds that imperfection back in on purpose, the same category of trick as Chromatic and EXIF-spoofing elsewhere in this pack - the photorealism playbook explicitly lists lens distortion alongside chromatic aberration and film grain as things real lenses produce that diffusion models rarely do.

The inputs and outputs that matter

Just two floats beyond the image, both -1 to 1 and defaulting to 0:

  • lens_distortion_k1 - the primary distortion coefficient. Positive values bulge the image outward from center (barrel distortion, the fisheye-adjacent look); negative values pinch it inward (pincushion). This is the knob that does almost all the visible work.
  • lens_distortion_k2 - a secondary, finer correction term. It shapes distortion further out toward the edges, on top of what k1 already does. Usually left small or at zero unless k1 alone is producing an unnatural-looking warp near the frame edges.

These are the same k1/k2 naming convention used in camera calibration and lens-correction tools - this node just runs the math in the direction that adds distortion rather than removing it.

One image output.

How to install it

Search ComfyUI-HakuImg in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone --recurse-submodules https://github.com/licyk/ComfyUI-HakuImg

Restart ComfyUI and find it under Image → HakuImg. No models, no submodule dependency for this particular node - it's geometric pixel remapping.

Common issues & troubleshooting

It looks like a fisheye gag lens, not a real camera. This is almost always k1 pushed too far. Real-world lens distortion at typical apertures is subtle - you'd measure it with a test chart, not eyeball it from across the room. Keep values in roughly the 0.05–0.2 range for something that reads as "a slightly imperfect but real lens" rather than a novelty effect. Save the extremes (closer to ±1) for a deliberate stylized look, not for realism.

Composition got cropped or warped unexpectedly at the edges. Distortion pushes pixels outward or inward from the center, which shifts what ends up near the frame boundary. If you need your final crop to land on a specific composition, apply this node before your final crop/resize step, not after - otherwise the warp can push content you wanted to keep right off the edge.

Combining with other realism post-processing. This pairs naturally with Chromatic and a light color-grade via Curve - real lenses distort geometry, fringe color at edges, and rarely produce the saturated, high-contrast output diffusion models default to. A small amount of each usually reads more convincingly than pushing any single effect hard.

Categoryimage/HakuImg

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
lens_distortion_k1FLOAT0.00-1–1
lens_distortion_k2FLOAT0.00-1–1

Outputs (1)

NameTypeDescription
imageIMAGE