Skip to content

Automatic Lens Distortion in Nuke from a Single Frame

October 17, 2026 · 8 min read

In VFX, every comp that puts CG into a plate has to match the lens the plate was shot through. Most of the time this boils down to two questions:

How strong is its distortion? Where is the distortion centered?

The usual answer is found with a lens grid shot on set and solved in 3DEqualizer, PFTrack or Nuke's LensDistortion. Without a grid, Nuke's CameraTracker and LensDistortion can also solve the distortion by tracking features through the shot, but only if the camera actually moves.

I explored a third option that avoids the need for a grid or a camera move (Nuke can also estimate distortion from a single frame by marking straight lines, but that still requires an artist to identify and trace suitable edges).

It's built on AnyCalib, an open-source network that predicts a camera ray for every pixel of an image. I fine-tuned it on real cine footage and on renders through Nuke's lens model, then converted those outputted rays to Nuke-compatible distortion coefficients for the LensDistortion node.

A glasshouse interior through a barrel lens, and undistorted by the node
Panorama: glasshouse interior, Poly Haven (CC0).

The basic workflow

The node is on GitHub, for Nuke 17 on Linux.

Connect a plate to the AnyCalib-Nuke node, then press Analyze.

  1. The node runs inference on the model via Nuke's bundled libtorch.
  2. Fits each pixel's predicted ray to calculate the likely distortionCenter.
  3. Calculates distortion1 (k1), distortion2 (k2) for the lens distortion model.
  4. Builds LensDistortion2 nodes or writes the STMaps directly.
AnyCalib in Nuke 17.

The viewer overlay draws the straight edges/lines the node found, green if the estimate straightens them and red if not.

The distorted plate (edges used, red) and undistorted (green).

Results

Tested against 341 plates of real cinema footage from 13 different locations.

The footage is InFlux (Liang et al., NeurIPS 2025): real footage from an ARRI Alexa Mini and two cine zooms, with the lens calibrated for every frame.

The fine-tuned model averaged a mean error of 5.36 px (measured against 1280px wide) on held-out footage.

Most cinema lenses are mild, so predicting no distortion at all is a relatively strong baseline, at around 8px. Stock AnyCalib doesn't clear that baseline unfortunately. It reads real lenses with too much barrel distortion and scores around 10px.

EstimateMean map errorAgainst doing nothing
No distortion8.34 pxbaseline
Stock AnyCalib9.97 px↑ 1.63 px worse
Straight edge refinement only7.10 px↓ 1.24 px better
Fine-tuned network5.81 px↓ 2.53 px better
Fine-tuned + straight edge refinement5.36 px↓ 2.98 px better

Undistortion map error: undistort a grid of points with the estimate and with the calibrated lens, and average how far apart they land from ground truth.

Here it is on one plate, each arrow the miss at one grid point:

Undistortion error of stock and fine-tuned on one plate
Undistortion map error on a real plate, arrows 4× real length.

Averaged over the whole test set:

InFlux test results
Mean map error on 341 real plates from InFlux locations.

The node is most useful on wide and mid lenses with real distortion. On long lenses and good primes, doing nothing still wins (see Limits).

How it works

From plate to undistorted plate
From plate to undistorted plate on one frame.

Under the hood, AnyCalib-Nuke does three things:

  1. Predicts a ray for every pixel. One line from the camera through each pixel, extending into the scene.

    • A distorted camera lens bends those directions, largely at the edges of the frame.
    • AnyCalib (Tirado-Garín and Civera, 2025) predicts these directions for each pixel in an image.
    • These predicted rays aren't tied to any one lens model, so Nuke's can be fitted to them afterwards.
  2. Fits Nuke's lens model to the rays. Nuke can't understand these predicted rays natively.

    • From the thousands of predicted rays, we need to figure out distortion coefficients used by Nuke.

    • Nuke's Classic model is one formula, where rr is a pixel's distance from distortionCenter:

      undistorted=distorted1+k1r2+k2r4\text{undistorted} = \frac{\text{distorted}}{1 + k_1 r^2 + k_2 r^4}
    • The node solves for the distortion values whose rays line up best with the network's.

  3. Straightens the edges. Lines that are straight in the scene should also come out straight once undistorted.

    • The node finds long lines the lens should have bent and nudges distortion1 and distortion2 until they're straight, while staying close to the network's answer.

Converting rays to distortion coefficients

We need to solve for five unknowns: focal length ff, radial distortion coefficients (k1k_1 and k2k_2 a.k.a Nuke's distortion1 and distortion2), and the distortion center (cx,cy)(c_x, c_y).

First, the distortion center.

Radial distortion only moves points towards or away from the distortion center, sliding along a fixed line. Thus, the pixel (x,y)(x, y) sits at an offset of (x−cx, y−cy)(x - c_x,\ y - c_y) away from the center.

Distorting and undistorting only scales the pixel along that offset.

We can use that to our advantage since the predicted ray's 2D component (dx,dy)(d_x, d_y) will be parallel to the pixel's offset from the center.

y−cyx−cx=dydx\frac{y - c_y}{x - c_x} = \frac{d_y}{d_x}

Cross-multiplying gives one equation per pixel, linear in cxc_x and cyc_y:

(x−cx) dy=(y−cy) dx(x - c_x)\,d_y = (y - c_y)\,d_x

Every pixel then draws a line along its ray, and least squares allows us to fit the likely distortion center.

Pixels spread around an image, each joined to its undistorted position on a line through the distortion center, with its ray pointing straight out along that same line; traced back, every line meets at the center

Now, solving for ff, k1k_1 and k2k_2.

For each pixel, you now know:

  • Distorted Radius rr: How far the observed pixel is from the distortion center.
  • Ray Direction (dx,dy,dz)(d_x, d_y, d_z): 3D direction pixel looks along, predicted by AnyCalib.
    • This ray tells us where the pixel would appear if projected through an ideal pinhole camera.

A ray (dx,dy,dz)(d_x, d_y, d_z) goes dzd_z forward and dx,dyd_x, d_y sideways.

We define the sideways-to-forward ratio:

s=dx2+dy2dzs = \frac{\sqrt{d_x^2 + d_y^2}}{d_z}

Projecting this ray onto an ideal image plane at focal distance ff gives:

ru=f⋅s{r_u=f\cdot s}

Comparing the Two

Nuke's Classic distortion model goes like:

ru=r1+k1r2+k2r4r_u = \frac{r}{1 + k_1r^2 + k_2r^4}

Substitute ru=fsr_u = fs

fs=r1+k1r2+k2r4fs = \frac{r}{1 + k_1r^2 + k_2r^4}

Rearranging:

rfs=1+k1r2+k2r4\boxed{\frac{r}{fs} = 1 + k_1r^2 + k_2r^4}

The left side is the radial distortion: how much the lens squeezed that pixel toward the center.

  • No distortion: Nothing gets squeezed, and it's 1 everywhere.
  • Barrel distortion: 1 at the center and drops below 1 toward the edges. k1k_1 sets how fast it drops, and k2k_2 adjusts the far corners.
  • Pincushion distortion: The opposite, rising above 1 toward the edges.
  • As r→0r \to 0, the distortion terms k1r2k_1r^2 and k2r4k_2r^4 approach zero, leaving:
f≈rsf \approx \frac{r}{s}
  • However, as rr increases, the r2r^2 and r4r^4 terms grow.
    • k1k_1 describes "first-order radial distortion", mostly controlling the central-ish region of the image.
    • k2k_2, "second-order", captures how distortion changes closer to the edges of the frame.
Side view of a pinhole: a ray through the hole lands at its undistorted position, f s from the distortion center on a sensor f behind it, while the lens squeezed the actual pixel in along the sensor to r. Beside it, the radial distortion r over f s against distance from the center: flat at 1 with no distortion, falling for barrel, rising for pincushion

To solve for the coefficients, rearrange the equation:

rs=f+fk1r2+fk2r4\frac{r}{s} = f + fk_1r^2 + fk_2r^4

Substitute a=fa=f, b=fk1b=fk_1, and c=fk2c=fk_2:

rs=a+br2+cr4\frac{r}{s} = a + br^2 + cr^4

This is now a linear least-squares problem in aa, bb, and cc.

  • Each pixel supplies one equation, and the solver does the work of finding the three values that minimize the total squared error across all pixels.
  • From this, we then finally recover the Nuke distortion values!
f=a,k1=ba,k2=caf=a,\qquad k_1=\frac{b}{a},\qquad k_2=\frac{c}{a}

LoRA Training

Why fine-tune. Stock AnyCalib learned from renders too, just not ones that look like actual everyday footage.

Half its training images were fisheyes, all of them barrel, and none had a field of view under 20°. Actual VFX plates tend to be a bit more mild with distortion, so it read them with too much barrel distortion, by ~39px at the corner on average.

One panorama, four cameras
One panorama, four cameras, each with its own FOV, lens, and orientation. Panorama: Leadenhall Market, Poly Haven (CC0).

Process:

Generate more synthetic frames. Ground truth is easy: pick a camera, render what it would see of a 360° panorama, and every pixel's ray is known exactly. The fine-tune rendered 65k+ new views through Nuke, from 82 panoramas outside AnyCalib's original training set.

  • Add additional sharpness falloff + vignetting to training set to simulate real lens behaviors around corners.
  • Additional grain and chromatic aberration artifacts were also added.

Incorporate real footage. Include real footage from cinema cameras with calibrated camera intrinsics. Exposes model to grain, visual defects, and other imperfections.

Fine-tuning. AnyCalib is a large DINOv2 backbone that reads the image, plus a small decoder and head that turn it into rays. The backbone stays frozen, with LoRA adapters on its attention and MLP layers to nudge how it reads a plate.

  • The decoder and head train in full. That's 22M trainable weights on an RTX 3090, and the adapters merge back in, so each model ships as a single TorchScript file.

Limits

Mild lenses. Predicting no distortion still beats the node on long lenses and quality primes. The network struggles when lenses have minimal distortion, often a few px at the corners.

Fisheyes. Undistorting a fisheye to a flat image throws the corners thousands of pixels out, and the node doesn't flag it reliably yet.

Anamorphic. The model + LoRA are trained for radial distortion. It doesn't estimate squeeze or target LensDistortion2's anamorphic presets yet.

What's next

  • Anamorphic output, through LensDistortion2's anamorphic presets.
  • A clearer flag for plates it can't handle, fisheyes first.
  • Finding more real footage with calibrated camera intrinsics for training.

The code is on GitHub.

Thanks to Javier Tirado-Garín and Javier Civera for AnyCalib, to Erich Liang, Jia Deng and the InFlux team for real footage with calibrated lenses, and to Poly Haven for the panoramas.