Lens correction module question


I’m confused about the ‘Lens Correction’ module. Sometimes it seems that I should use it, but sometime the lines get crooked. This happens especially when zoomed.

For example, I shot two pictures into RAW and JPEG (yes, I know they are not focues properly, but that’s not the point :wink: - base and zoomed. Both with the same camera with the same lenses but different focal distance.

JPEGs look like what i saw on my live view display on my camera during taking the photo and then after checking it. The raw file for one of them looks similar to appropriate jpeg when i apply the lens correction. The other raw, however, seems correct without the lens correction module and after applying the lines are crooked.

Any idea why this could be?

I attached the zoomed file (zoomed.jpg and zoomed.cr3) which looks incorrect with the lens correction module applied on raw file. The base file (base.jpg and bease.cr3) looks correct after applying the lens correction to the raw. I also attached the screenshots from darktable with the zoom.cr3 file opened with and without the lens correction module active.


I’m using the Canon EOS 90D camera with Canon EF-S 18-135 IS USM lenses

In my camera I have all lens corrections set to ‘ON’:

peripheral illum correction, distortion correct, digital lens optimizer

I have darktable 3.8.1 running on Ubuntu 22.04 64bit

Here are the versions of liblensfun I have installed:

ii liblensfun-bin 0.3.2-6 amd64 Lens Correction library - Utilities
ii liblensfun-data-v1 0.3.2-6 all Lens Correction library - Data
ii liblensfun1:amd64 0.3.2-6 amd64 Lens Correction library - Runtime files
ii python3-lensfun 0.3.2-6 amd64 Lens Correction library - Python3 module

Thanks for any suggestions,


zoomed.cr3 with lens correction applied (see the top line is crooked)

zoomed.cr3 without lens correction applied (see the top line is straight)



Here are the appropriate RAW files:
base.CR3 (36.7 MB)
zoomed.CR3 (37.3 MB)

Lensfun has only one distortion correction distance for focal length. For vignetting it has multiple distances.

When creating a distortion correction profile for Lensfun you focus 10 m away. Not 0,6 m. The drawback is that you can’t use a profile created at 10 m distance for something 0,6 m away.

Do you get similar issues zoomed in and at 10 m or more? If so the profile may be wrong.


thanks for the answer. But I’m not sure if i really understand what does it mean :slight_smile:
So basically the ‘lens correction’ can only work correctly with my lenses if i’m taking picture of something at the distance 10m or more, is that right?
If so, is there anything I can do if I want to process raw files taken from shorter distance?


Yes, you can create a profile yourself with the distance you like. But make sure the problem is distance first.

Thanks, I’ll give it a try

Well, I’ve done some testing and now i’m even more confused.
It seems that it doesn’t really depend on the distance of the object being photographed. What seems to be the main factor is the actual focal length on the lens (zoom). I don’t really understand how lensfun works, but this is what I’ve found in slr-canon.xml for my lens:

         <model>Canon EF-S 18-135mm f/3.5-5.6 IS USM</model>
         <model lang="en">Canon EF-S 18-135mm f/3.5-5.6 IS USM</model>
         <mount>Canon EF-S</mount>
             <!-- Taken with Canon EOS 7D Mark II -->
             <distortion model="ptlens" focal="18" a="0.03582" b="-0.10962" c="0.05876"/>
             <distortion model="ptlens" focal="24" a="0.02725" b="-0.07222" c="0.04826"/>
             <distortion model="ptlens" focal="35" a="0.00909" b="-0.01398" c="0.01265"/>
             <distortion model="ptlens" focal="50" a="0.00816" b="-0.01410" c="0.01941"/>
             <distortion model="ptlens" focal="85" a="0.00335" b="-0.00234" c="0.01238"/>
             <distortion model="ptlens" focal="135" a="-0.00485" b="0.02086" c="-0.00627"/>
             <tca model="poly3" focal="18" br="-0.0000934" vr="1.0006986" bb="0.0000610" vb="0.9999352"/>
             <tca model="poly3" focal="24" br="-0.0000839" vr="1.0003945" bb="0.0000671" vb="1.0001346"/>
             <tca model="poly3" focal="35" br="0.0000158" vr="1.0001578" bb="-0.0000026" vb="1.0001780"/>
             <tca model="poly3" focal="50" br="-0.0000138" vr="1.0002028" bb="-0.0000194" vb="1.0000375"/>
             <tca model="poly3" focal="85" br="0.0000344" vr="0.9999689" bb="-0.0000522" vb="0.9998853"/>
             <tca model="poly3" focal="135" br="0.0000385" vr="0.9995855" bb="-0.0000297" vb="0.9999159"/>

First thing is that I have different camera than mentioned in the comment (I have EOS 90D while the data were collected with EOS 7D MkII according to the comments).
I’ve tried to recompute cropFactor to match the size of my processor. It made some differences, but still some pictures are not correct after applying the lens correction.

Also, I’m confused about the distortion section in the xml file.
Do I understand it correctly, that lensfun can only work with these few focal lenghts?
Because, honestly, it sound kind of absurd that in darktable I can only make correct perspective if the picture was taken with one of 6 possible focal lengths.
Otherwise the ‘lens correction’ doesn’t work properly. It’s kind of hard to believe that if someone uses Linux and want to process the raw files taken with the lens with zoom, then the zoom is significantly limited to few numbers (which are also hard to match in real conditions exactly).

Is there som more mature library, that can work with lenses allowing zoom? Or is this really just a case “don’t zoom if you want to use Darktable”.

Canon has a software on it’s own for processing RAW files which can correctly fix distortion. But it’s kind of ‘clumsy’, it has far less options and modules that Darktable and it doesn’t work in Linux at all (even using wine).

Any help appreciated,

I think you have misunderstood lens correction and what it does. In your original photo, it looks like you’re camera sensor is not completely parallel to the paper you’re trying to photograph, so when you apply the lens correction, it appears to make it worse.

I think you probably want the Perspective Correction module, which will make all the lined in the photo square to the image border. You probably want lens correction on too.

When you’re just applying lens correction to photos (and not taking photos to make an actual profile, which is what the video above is talking about), then the distance doesn’t matter. If you’re taking photos to create a lensfun profile, then distance does matter.

I’m not a canon user, but aren’t both of those cameras APS-C size sensors? If yes, no need to change anything.

Lensfun will interpolate the results for other focal lengths. If you want to create your own super precise profile, you can shoot more than 5 focal lengths, but 5 is considered enough generally.

No, lensfun is it and its used by commercial software as well. The quality of the corrections are generally quite good.

For some newer cameras, correction metadata is in the file, but not for DSLRs generally.

Perhaps of you tell us what you’re trying to do we can be of more help.

the sample in your post doesn’t contain distance related corrections. That’s quite common with lensfun since taking pictures for profiling using several focal length and also several distances for each focal length takes a lot of time.
Since lensfun interpolates the values you can vary the correction by manually overriding the focal length (or distance if in the profile) setting to improve the result

btw: no one knows better correction algorithms for canon lenses than canon - but they didn’t published them…

Lensfun has no focus distance for distortion. Only for vignetting.

Distortion correction profile only needs Hugin and no Python scripts. Watch the YouTube tutorial and create a decent profile from 18-135 mm. You can have 117 distortion correction parameters for that lens, but I don’t think your lens will report as many in Exif. Often when I have tried I get 18, 23, 25, 30 etc.


I didn’t know about that module. You’re right that when I was testing this i was not 100% parallel with the paper.

They are both APS-C, but with slightly different crop factor (1.605 vs 1.613 - i’m not sure whether this does any differnce).
About the distortion for specific focal length, it really sounded weird that it would support only specific modes, so thanks for clarfying that.

All what’s being written make complete sense, but what still confuses me is that the jpeg (or the raw processed in canon’s software) just looks much more straight and correct than the raw with lens correction module applied in darktable (or the raw without lens correction).

Nothing says that the profile you use is 100% correct.