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.

The basic workflow
The node is on GitHub, for Nuke 17 on Linux.
Connect a plate to the AnyCalib-Nuke node, then press Analyze.
- The node runs inference on the model via Nuke's bundled
libtorch. - Fits each pixel's predicted ray to calculate the likely
distortionCenter. - Calculates
distortion1 (k1),distortion2 (k2)for the lens distortion model. - Builds
LensDistortion2nodes or writes the STMaps directly.
The viewer overlay draws the straight edges/lines the node found, green if the estimate straightens them and red if not.
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.
| Estimate | Mean map error | Against doing nothing |
|---|---|---|
| No distortion | 8.34 px | baseline |
| Stock AnyCalib | 9.97 px | ↑ 1.63 px worse |
| Straight edge refinement only | 7.10 px | ↓ 1.24 px better |
| Fine-tuned network | 5.81 px | ↓ 2.53 px better |
| Fine-tuned + straight edge refinement | 5.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:

Averaged over the whole test set:

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

Under the hood, AnyCalib-Nuke does three things:
-
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.
-
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 is a pixel's distance from
distortionCenter: -
The node solves for the distortion values whose rays line up best with the network's.
-
-
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
distortion1anddistortion2until they're straight, while staying close to the network's answer.
- The node finds long lines the lens should have bent and nudges
Converting rays to distortion coefficients
We need to solve for five unknowns: focal length , radial distortion coefficients ( and a.k.a Nuke's distortion1 and distortion2), and the distortion center .
First, the distortion center.
Radial distortion only moves points towards or away from the distortion center, sliding along a fixed line. Thus, the pixel sits at an offset of 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 will be parallel to the pixel's offset from the center.
Cross-multiplying gives one equation per pixel, linear in and :
Every pixel then draws a line along its ray, and least squares allows us to fit the likely distortion center.

Now, solving for , and .
For each pixel, you now know:
- Distorted Radius : How far the observed pixel is from the distortion center.
- Ray Direction : 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 goes forward and sideways.
We define the sideways-to-forward ratio:
Projecting this ray onto an ideal image plane at focal distance gives:
Comparing the Two
Nuke's Classic distortion model goes like:
Substitute
Rearranging:
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. sets how fast it drops, and adjusts the far corners.
- Pincushion distortion: The opposite, rising above 1 toward the edges.
- As , the distortion terms and approach zero, leaving:
- However, as increases, the and terms grow.
- describes "first-order radial distortion", mostly controlling the central-ish region of the image.
- , "second-order", captures how distortion changes closer to the edges of the frame.

To solve for the coefficients, rearrange the equation:
Substitute , , and :
This is now a linear least-squares problem in , , and .
- 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!
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.

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.
Related Posts
PyTorch in Nuke: Building a Next-Node Predictor
How to train and run a PyTorch model on the libtorch that ships with Nuke 17, without installing torch, then using it to build NodeScout, a next-node predictor for Nuke.
Understanding Nuke's '.nk' file structure
Understanding and parsing Nuke's '.nk' file structure