# Lens Distortion Correction

Gilles
Caulier

    caulier dot gilles at free.fr

Gerhard
Kulzer

    gerhard at kulzer.net

The digiKam image plugin Lens Distortion is a tool to correct spherical lens aberrations on the photos. It uses an algorithm copyrighted by David Hodson.

KDE
Digikam

# Introduction

Barrel distortion is associated with wide angle (or minimal zoom) lenses. It causes the images to appear slightly spherical (curved outward) like a barrel. You can notice this when you have straight features close to the image's peripheral sides. Pincushion distortion is the opposite defect and is associated with Telephoto lenses (maximum zoom) or underwater pictures. The images appear pinched (bent inward) toward the center. The Pincushion is often less noticeable than barrel but are equally visible near the edges. These distortions can easily be eliminated without visible loss in quality with this plugin.

This plugin treats the geometrical distortions. Chromatic abberations will not be corrected by this plugin.

The following figures explain the main types of geometrical distortions:

- (1): pincushion distortion.

- (2): no distortion.

- (3): barrel distortion.

## Lens Distortion Types

## Using the plugin

A bit of explanation first. The geometrical corrections use 4th-order polynominal coefficients.

- The 1st-order coefficient changes the size of the image. The plugin calls this Zoom.

- The 2nd-order coefficient treats the main geometrical distortion of lenses and can correct the convex or concave shape of the image.

- The 3rd-order coefficient has a similar rounding effect but levels off towards the edges. This correction is not employed in the plugin.

- The 4th-order coefficient corrects the far edges inversely to the 2nd-order rounding. Combining it with the 2nd-order correction the geometrical distortions can be almost completely eliminated.

### Lens Distortion Correction Dialog

Four sliders let you set the distortion correction filter:

Main: this value controls the amount of 2nd-order distortion. Negative values correct barrel distortions, while positive values correct pincushion distortion.

Edge: this value controls the amount of 4th-order distortion. The Edge control has more effect at the edges of the image than at the centre. For most lenses, the Edge parameter has the opposite sign of the Main parameter.

Zoom: this value rescales the overall image size (1st-order correction). Negative values zoom out of the image, while positive values zoom in.

Brighten: this control adjusts the brightness in image corners. Negative values decrease the brightness image corners, while positive values increase it.

To help you to choose the best filter settings, the plugin dialog illustrates with a thumbnail preview the distortion correction applied to a crossed mesh pattern. The values you apply to your image will be saved and come up with the same values as default the next time you call the plugin.

The barrel-pincushion correction should be done before any crop or size changes (including perspective correction). In fact the Barrel-Pincushion corrections should be the very first step on the original image. If you crop the image and then use barrel correction the effect would be obviously wrong.

To help you finding the best correction the tool provides a vertical and horizontal guide. Move the mouse cursor in the image preview to display the dashed lines guide. Move the cursor to an important place in the image like the sea level or a building border and press the left mouse button for freeze the dashed lines position. Now, adjust the barrel/pincushion correction to align with the guide.

When using pincushion correction the resulting image will have a black border in the corner. You will need to cut this out with a crop tool available in Transform Crop Image Editor menu or via the zoom slider of this dialog.

On most images using the barrel correction is enough, however with some shots such as front pictures, frames, paintings, the next logical step is to use perspective correction to make all the angles 90 degrees. Note that when you hold your camera by hand you almost always introduce some kind of slight perspective distortion.

## The plugin in action

This is an example of a barrel correction applied to church in north Norway. The original image is (1), the corrected image (2).

The values used for this example are:

- Main = -40.

- Edge = 0.

- Zoom = -20.

- Brighten = 0.

### Lens Distortion Correction Preview