Estimating and Removing Lens Distortion Using Lines

Line analysis estimates the distortion from lines drawn manually along features in the input that are known to be straight. This can be useful if there is no grid available or if you have a grid for your sequence but the grid analysis failed, for instance due to bad lighting.

The LensDistortion node's Analysis tab has a number of tools for selecting and drawing features and lines in the Viewer:

 

Select - a multi-purpose tool used to select, move, and delete features and lines.

 

Select Feature - used to select, move, and delete features. You cannot affect lines using this tool.

 

Select Line - used to select, move, and delete lines. You cannot affect features using this tool.

 

Add Feature - used to add, select, and move features on existing lines. You cannot affect lines using this tool.

 

Remove Feature - used to delete features from existing lines. You cannot affect lines using this tool.

 

Add Line - used to add and delete lines and features.

To estimate lens distortion using lines, do the following:

1.   Examine the source footage for distorted lines that are known to be straight. If you have a grid, this is simple, but real life examples include walls, railings, roads, and so on.
2.   Select the Add Line tool and start to add points along the distorted lines by clicking in the Viewer.

3.   You can add features to existing lines using the Add Feature tool. This give you finer control of lines in the Viewer.

Tip:  When you've finished drawing a line, either select a different tool or press Enter to finish the current line before starting another.

Tip:  You can adjust the position of features and lines using the selection tools in the Viewer.

4.   The solve requires at least as many lines as there are Distortion Parameters to calculate the distortion. In the case of NukeX Classic, two vertical and two horizontal to cover the Denominator and Centre parameters. Good line drawing practices include:

Drawing lines with three or more features - lines with only two points are ignored.

Drawing longer lines - they contain more useful information on the curvature resulting from lens distortion.

Distributing lines evenly - avoid biasing the solve by covering as much of the image as possible.

The following example shows a typical set of lines.

The original distorted shot

Example lines in the alpha channel

5.   Click Solve to calculate the distortion, there's no need to run the Detect step with manual features and lines.

Note:  The Solve button is disabled if there are not enough lines for the detection computation.

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

Note:  Clicking Solve again can improve the result in some cases.

Tip:  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 lines expand beyond the bounding box of the footage, which can mean you're losing image data.

6.   Set the Output Format control to Format 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 feature lines 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 area at the bottom of the image in the center shows overscan.

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