All photographic lenses have different types of errors. Three of them can be corrected by software almost losslessly: distortion, transverse chromatic aberration, and vignetting. The Lensfun library provides code to do these corrections. Lensfun is not used by the photographer directly. Instead, it is used by software such as Darktable, Rawstudio, UFRaw, digiKam, ImageMagick, and others. For example, you import a RAW into Darktable, Darktable detects the lens, focal length, and f number used for this photograph, and it then calls Lensfun to automatically rectify the photograph. Great, isn’t it?

Lensfun uses a database to know all the parameters needed to do the lens corrections. This database is filled by photographers like you, who took time to calibrate their lenses and to submit their findings back to the Lensfun project. If you’re lucky, your lens models are already included. If not, please use this manual to do the calibration and contribute your results. You help yourself and others.

Okay, let us assume your lens model isn’t yet covered by Lensfun, or not good enough. The following sections show you how to create an entry of your own. Note that you needn’t do all of this. Do whatever your spare time allows. Lensfun is very flexible.

Note

I set up a lens calibration service. If you don’t want or cannot do the calibration but at least can take the calibration pictures, upload them there.

First, have a look at the screencast at Vimeo. It gives you an overview. Additionally, it demonstrates how to do the actual calibration with the Hugin panorama stitcher. Unfortunately, the video refers to an older version of Hugin. Since 2014, Hugin uses a different user interface. If you know Hugin, you probably are able to map the workfow to the new UI.

Take the test photographs [1]. Put the RAWs in the directory distortion/. If you don’t have a lenses.txt yet, call calibrate.py from the root directory. It will generate a template lenses.txt file, plus TIFFs from all RAW files in distortion/ ready-to-be-used for Hugin. Complete the lens lines in lenses.txt.

Now use Hugin to do the calibration as shown in the screencast, and copy-and-paste the resulting values for (a), (b), and (c) into lenses.txt.

Repeat this for every lens. For zoom lenses, repeat this for every focal length that you calibrate.

Look for a large object with sharp high-contrast edges throughout the image. Preferably, the edges should be black–white but anything close to that is sufficient. Assure that there are such edges in the corners, too. In many cases, you can use the very same pictures for distortion and chromatic aberration correction, but TCA doesn’t need the straight lines.

You should take your pictures being at least 8 metres away. For zoom lenses, take pictures at the same focal lengths as for distortion. Take really sharp pictures.

You need a diffuser in front of the lens. This may be translucent milk glass, or white plastic foil. Whatever, as long as it is opaque enough so that nothing can be seen through it, yet transparent enough so that light can pass through it. It must not be thicker than 3 mm. It shouldn’t have a noticeable texture. It must be perfectly flush with the lens front, and it mustn’t be bent. It must be illuminated homogeneously.

As an example, my own diffuser was white plastic foil taped on a piece of ordinary glass for stability. I illuminated the ceiling of my room with an uplight, pointed the camera upwards and put the foil without a gap on the lens. Then I took the pictures.

Switch your camera to RAW mode. Make sure that no corrections are applied by the camera (some models do this even for RAWs). Set the camera to “aperture priority” and the lowest ISO. Switch on manual focus.

Focus at infinity. (Despite the foil directly in front of the lens.) Take pictures at maximal aperture and at three smaller apertures in 1 stop distance, and at the minimal aperature. For zoom lenses, take pictures at five focal lengths. This makes 5 pictures for primes and 25 for zooms.

(I don’t recommend doing the following because the gain in accuracy is really very small for the lenses I’ve seen so far.)

Lensfun can correct vignetting depending on distance. Thus, you can achieve a little bit more accuracy by shooting at different distances. Additionally to focus at infinity, repeat the procedure with focus at the near point [2]. Further senseful distances are near point times 6 and near point times 2, in this order. This means up to four different distances. But again: This is not necessary. If it sounds too tedious to you, shooting at infinity is sufficient.

Put pictures for distances other than infinity in vignetting_<distance>/. For example, pictures for 20 cm belong in vignetting_0.2/.

For every focal length/aperture/distance triplett, you can take more than one picture, possibly with moving the foil a bit or with tilting the camera a bit. calibrate.py will detect such equivalent pictures, and will take the average.

If you cannot get a picture of a building in your vicinity, don’t worry. Most lenses don’t need the full 8 metres of distance. What really matters are the long straight lines. But avoid anything closer than one metre.