Estimating Lens Distortion Using a Grid

Grid analysis estimates the distortion from a checkerboard or thin line grid. As a general rule, if you have a grid you can use to calculate your lens distortion, you should use grid analysis. Grids are constructed from Features and Links, which can be calculated separately to allow for manual corrections or all at once automatically.

The original distorted shot

The distorted grid associated with the shot

To estimate distortion using a grid:

1.   Read in your grid and connect a LensDistortion node, followed by a Viewer.
2.   Set the lens Type and Projection using the dropdowns in the LensDistortion Properties panel. In this example, the lens is Spherical and Rectilinear, but there are a number of other presets included.
3.   If you're using a fisheye lens, you need to 'defish' the lens. You can do this by selecting the correct Projection setting, such as Fisheye Equisolid, entering the Focal Length and Sensor Size.

Tip:  If you don't know the Focal Length, switch the Output Mode to Undistort and adjust the Focal Length until the curved lines in the image appear approximately straight. Don't forget to switch back to Mode > STMap before continuing.

4.   Set the Distortion model preset to use for the estimation. Nuke ships with several models for use with CaraVR and 3DEqualizer, as well as a NukeX Classic model.

The model you choose sets appropriate Distortion Model controls and populates the read only Distortion Equation fields showing the math involved in the estimation.

5.   The LensDistortion node adds a keyframe on the current frame automatically, but you can add more using the or Key All buttons.

Adding keyframes can produce a better result for long sequences, but it takes longer to calculate the result.

6.   Click Detect to start the grid calibration. By default, Nuke looks for Features on the grid and then creates Links between those features to create the distortion grid.

Tip:  For difficult shots, you can make adjustments between Features and Links detection to improve the results. See Adjusting Grid Detection Parameters for more information.

A grid overlay is displayed when the detection step is complete.

Tip:  If the grid does not cover most of the image, try increasing the Number of Features value on the Grid Detection tab and clicking Detect again.

7.   Click Solve to estimate the distortion using the grid.

Nuke estimates the distortion and displays a new overlay and overall Solve Error.

Green lines represent links that fall within the Threshold value and red lines those that fall outside the Threshold. You can hover over links to display their solve error.

8.   Clicking Solve again can improve the result in some cases. You can also refine the detection and linking before solving again using the controls on the Grid Detection tab. See Adjusting Grid Detection Parameters for more information.
9.   When you're happy with the solve, switch the Output Mode to Undistort.

Note:  You can also output the distortion as an STMap for use in other images. STMaps contain the pre-computed warp data in the motion channel, allowing you apply the warp quickly and easily. See Working with STMaps for more information.

Nuke takes the estimated distortion and uses the result to 'straighten' the feature links.

You may notice that the grid expands beyond the bounding box of the footage, which can mean you're losing image data.

10.   Set the Format control to Reformat and select a larger format to include the grid. For example, if your original grid is UHD_4K, you might reformat to 8K_LatLong.

Reformatting the grid deforms it into a characteristic bow tie shape. Any areas of the image where there is no data are overscanned, meaning the last pixel available is duplicated to the edge of the format. The areas at the top and bottom of the image in the center show overscan.

11.   If you don't want to reformat the image, or only a small amount of the image is missing, you can bring more image data into the format bounds using the Adjust Format controls.
12.   Enable Override and then use the Add Pixels and Adjust Aspect controls to enlarge the format as required.

The new format is called lens_distortion_adjusted by default, but you can enter any name you choose in the adjustedFormatName control. The new name is then added to the Project Settings > Format dropdown after adjustment to avoid changing Nuke's default formats.

Tip:  You can also preserve overscan data by increasing the bounding box. The Add Pixels control allows you to add an equal number of pixels on all sides of the image or you can edit the bounding box manually by enabling Override and using the outputBBox controls.

13.   Proceed to Removing Lens Distortion from an Image or Adjusting Grid Detection Parameters to fine tune your grid.