Removing Lens Distortion from an Image

After estimating the lens distortion from a reference grid, you can use the warp to remove the distortion from your sequence before performing comp work. The easiest way to do this is to copy and paste the LensDistortion node that was used to generate the warp and connect it to your sequence.

Note:  You can also use STMaps to remove and apply distortion. See Working with STMaps for more information.

1.   Read in the sequence from which the reference grid was taken.
2.   Copy and paste the LensDistortion node containing the grid analysis (described in Estimating Lens Distortion Using a Grid), then connect it to the sequence and a Viewer.

The distortion is removed from the sequence in the Viewer.

The original plate

The undistorted plate

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

3.   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.

You can now apply your VFX work before redistorting the plate back into its original state.

4.   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.
5.   Enable Override and then use the Add Pixels and Adjust Aspect controls to enlarge the format as required.

Note:  You can use expressions to control the number of pixels added as a percentage of the format by right-clicking the Add Pixel control and selecting Add Expression. For example, input.width*0.05 adds pixels equal to 5% of the input format's width.

The undistorted format

The adjusted format

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.

6.   You can now track, matchmove, composite, and so on in the undistorted space before redistorting the image. See Applying Lens Distortion to an Image for more information.