Getting lens correction module in darktable to match lensfun the lenfun database in Windows

Hi All,

I’m using darktable on Windows (11) and I’m not getting the contents of the lensfun database to match the available lenses shown in the list of lenses from the lens correction module in DT. Is this expected behavior? Is there a configuration I need to set in DT to get the lenses to display/match? Or does the lens in the lensfun DB need to match the model in the exif data from the image?

The specific lens I’m trying to find is an EF 75-300mm, but neither of the two listed in the lensfun XML file are present in that list in DT.

I’ve tried a direct windows installer that was downloaded from the DT website, as well as a successfully compiled instance on my machine after successfully running lensfun-update-data.

Any thoughts or suggestions are appreciated.

Thanks,

Dave

Hi @dlavallee welcome to the community!

Determining lens names is a hard problem, especially in older cameras. The identifier that is in the metadata of your raw file is an integer, and exiv2 tries to map that onto a lens name. The problem is that different lenses often use the same integer for identification.

You can read more at Exiv2 - Image metadata library and tools under the section " 12 CONFIGURATION FILE". But the short of it is:

  1. Find where your config file lives: exiv2 --verbose --version --grep config_path
  2. Find out the integer value for your lens: exiv2 --print v --grep lens/i <your raw file>
  3. Make an entry in your config file that maps the integer onto Lensfun’s name for the lens:
[canon]
146=Your Lens Name from Lensfun

Save the file.
4. Restart darktable and use the button “Refresh EXIF” in the Lighttable module Actions on Selections > Metadata tab > Refresh EXIF.

Now the name detected by darktable should match the Lensfun lens name and be autodetected by the Lens Correction module in darktable.

2 Likes

I should really formalize this into an article on the pixls.us blog :upside_down_face:

5 Likes

there’s also a section on this topic in darktable GitHub wiki: User's portal · darktable-org/darktable Wiki · GitHub

2 Likes

Thanks so much for this!

you could extend the lens profiling blog post we have already.

Thank you for the detailed suggestion. I tried this for both the lens and the camera (which was already listed properly, but it was no help either). I tried first with just the lens data an then tried the camera model data. I should point out that the module is listing the lens properly now, but when I click to turn on the lens correction, I get a “camera/lens not found” error.

As I said originally, when I try to choose a lens from the module (after getting that error), I get a display of a list of lenses, but that list does not match what’s in the lensfun XML. For example two different lenses of 75-300mm f/4-5.6 are listed in the lensfun database (one of them is mine), but the list of lenses from the module in darktable have neither lens listed. This happens for both: the system install of darktable on Windows and the compiled build install in my UCRT64 environment.

Have you pulled in a recent version of all the lens profiles for lensfun?

Have you pulled in a recent version of all the lens profiles for lensfun?

Yes. Both are latest.

DT is at 5.1.0+957 (compiled on my Windows 11 machine within the UCRT64 environment).

I’m also getting the same result on my system install of DT 5.0.1 on Windows.

Is it normal that the list of available Canon lenses from the module do not match the lenses in slr-canon.xml? If not, maybe I have a config issue?

Of note:

  1. The lensfun database files are under darktable/share/lensfun/version_1/
  2. The parent element in slr-canon.xml is ‘’

Thanks in advance for your help on this.

There indeed is known (to me?) “relocation” bug wrt lensfun and MSYS2 builds. Namely, it can only see the main database in e.g. /ucrt64/share/lensfun/version_1/, but not the updates in /ucrt64/var/lib/lensfun-updates/version_1/.

So the current workaround is to move the updates to the main location manually. (Which is pretty much how the official Windows installer does it, just that the “root” is not ucrt64 but the darktable install folder, i.e. lensfun looks for its db relative to bin/darktable.exe/../)

This is because of how lensfun builds up relative paths internally - it of course assumes it’s running on *nix only where things work out nicely. I have tried patching this, but haven’t gotten it to work yet…

P.S. We could actually report this to MSYS2 as a packaging bug/enhancement request, and hope someone else has the time/interest to take a stab at it as well…

Thank you very much for your feedback. I (now) have the lenses I’m looking for in:
/ucrt64/share/lensfun/version_1/slr-canon.xml
/opt/darktable/share/lensfun/version_1/slr-canon.xml

As well as for the Windows system install of darkktable:
C:\Program Files\darktable\share\lensfun\version_1\slr-canon.xml

Both instances (windows system install and the compiled install) of DT are getting the same results: some of the lenses in slr-canon.xml are not visible for selection within the lens correction module in darktable.

FYI, the two lenses I’m looking for are as follows (I didn’t check any others):
Canon EF 35-135mm f/4-5.6 USM
Canon EF 75-300mm f/4-5.6 III

Might also be a problem of body mount vs lens mount incompatibility (incompatible combos are not available and not shown for selection).

Also the crop factor is important - if a lens was profiled on an APS-C body (which seems to be the case for the two you mentioned), it won’t be available/shown for a FF one…

Other than that, if the lens popup list is very long I did notice it is sometimes hard/impossible to scroll in Windows, or there is maybe a syntax error in the XML?

Thanks for your feedback. Yes, this is the issue! I wasn’t sure why there was a crop factor for an EF lens (since it is a full frame compatible lens).

Now I get it: the data was generated using a crop factor (APS-C) body, correct?

So I need to make my own calibration entry using (for example) Torsten Bronger’s tutorial and python script for each lens, correct?

This will take a bit, but I will do this and if I get good results I’ll send them to the folks at lensfun.

Thank you so much for uncovering the issue!

Following up on:

I was thinking that it was just the entire list for the camera. Of the 4 groups, one group of lenses was pretty while another was very long. The other two were groups of 1 and 5.
A quick spot-check of several lenses in the different groups confirm that there is a CF of 1.0+ available for the lenses shown.