Lensfun - getting it to work with darktable

I have had some luck with hand editing the lensfun database. I get the exact character strings the camera/lens reports from the image information in the Lighttable view. Then I add or replace the database entry.

So, while it may look like your camera/lens is correctly shown in the Lens Correction module, if there is even an errant space or dash character from that given by the EXIF info, you will get the error message that it cannot be found.

Also, this means that the next time the database is updated, you may have to edit it, again.

under linux, you can also create a file .exiv2 under your home directory, with a structure like:
[sony]
28=Tamron SP AF 90mm F2.8 Di Macro

i.e. a section per camera (body) brand, then for each lens a line with
<lensID>=<lensfun name>

This will make the exiv2 library use the name you specified for the given lens ID, overriding the default name.

See the exiv2 manpage for exact details

Can you look in the xml file in the lensfun folder and confirm the info matches your exif data…if not you could modify them to match…

Modifying the lensfun xml files would work as well,
until the next update of the lensfun database or exiv2.

Afaik, the actual lens name is not stored in the image metadata (improbable or impossible for 3rd party lenses anyway…), it’s the exiv2 library that generates the lens name from the lens ID taking into account the camera brand. Each manufacturer has its own IDs for his lenses…

1 Like

Yes, I did so for a Tamron Zoom before it appeared in the database with a matching name. But it is annoying to repeatedly do this after updates of the involved tools.

I’m not a dt programmmer, so I don’t know how exactly the program is acting to achive the matching lens. Using exiftool I get the following entries for a Sony macro lens regarding the lens :

[EXIF]          0xa432 Lens Info           : 50mm f/2.8
[EXIF]          0xa434 Lens Model          : 50mm F2.8 Macro
[MakerNotes]    0xb027 Lens Type           : Minolta/Sony AF 50mm F2.8 Macro (D) or F3.5
[MakerNotes]    0xb02a Lens Spec           : Unknown (00 0 0 0 0 00)
[MakerNotes]    0x0603 Lens Format         : Full-frame
[MakerNotes]    0x0604 Lens Mount          : A-mount
[MakerNotes]    0x0608 Lens Type           : Minolta/Sony AF 50mm F2.8 Macro (D) or F3.5
[MakerNotes]    0x0105 Lens Mount          : A-mount
[MakerNotes]    0x0106 Lens Format         : Full-frame
[MakerNotes]    0x0109 Lens Type           : Minolta/Sony AF 50mm F2.8 Macro (D) or F3.5
[MakerNotes]    0x0115 Lens Spec Features  : Macro
[Composite]          - Lens ID             : Minolta/Sony AF 50mm F2.8 Macro (D)

It would be very interesting for me to know which tag is used for identification. I guess it is the Composite tag “Lens ID”. Possibly a dt coder could give some insight or just point to the source code where identification is implemented. The dt manual only says : “darktable finds this data in your image’s Exif information”.

Update: did an intens search and found darktable/master/src/common/exif.cc. As far as I understand mainly tags of type “LensModel” are used, by different handling for different manufacturers. Special treatment of Sony SAL lenses where aditionally the tag “LensID” is used.
After I saw this code I have compassion for the programmers and great respect handling this mess of information being provided by the manufacturers in a very inconsistent way.

1 Like

If you want to find the identifier, use this command:

exiv2 -pv --grep lenstype/i <image>

Then find the lens name, keeping in mind that the lens name must match what is in lensfun’s database:

exiv2 -pa --grep lenstype/i <image>

Then stick those values in ~/.exiv2

Yes, this is the analogon to what I did with exiftool only being executed by exiv2. But this does not answer the question how identification is explicitly done. See update of my recent post.

Yes, it is inconsistent, to say the very least…

For exiftool, keep in mind that you need the -n switch to see the actual metadata values; exiftool uses internal lookup tables to put nice text nomenclature in its default lens tags.

There isn’t a single tag that is used for identifying a lens that doesn’t have a name in exiv2, its uses several tags to try and figure it out.

I took a closer look into the source code and I think I understand now, how identification is done in all detail. Shame on the manufacturers !!! And thank you for the -n tip, but I am already using it in combination with some others to do some formatting of the output.

1 Like

Until the Z cameras, Nikon AFAIK didn’t include a text nomenclature for the attached lens in any NEF metadata. Hence the exiftool amalgam [Composite]LensID tag, which if extracted with -n gives an eight-digit hex number like this:

[Composite]     Lens ID                         : 8B 40 2D 80 2C 3C FD 0E

These eight values are a concactenation of values from the following tags: LensIDNumber, LensFStops, MinFocalLength, MaxFocalLength, MaxApertureAtMinFocal, MaxApertureAtMaxFocal, MCUVersion and LensType, and is used to look up a text value in a humongous table. See this described here:

https://exiftool.org/TagNames/Nikon.html

Scroll to the bottom of the page.

With the new Z cameras, Nikon is now putting a text nomenclature in the EXIF Lens Model tag:

[EXIF]          Lens Model                      : NIKKOR Z 24-70mm f/4 S

Yay. I think they needed to do this because they are now apparently using software correction as a lens design trade, sacrificing distortion for resolution, and they need to clearly communicate the lens to the downstream software that is expected to correct the distortion. Lightroom won’t let you turn off the correction for this lens…

3 Likes

Interesting information, shows in impressing manner how manufacturers are wasting time and energy of programmers having to deal with this information chaos. It could be so easy…

It’s not only the fault of the camera makers, have a look here:
https://exiftool.org/TagNames/Sony.html#LensType
Scroll down to the section “Sony LensType Values” and note the impressive number of lenses giving as ID ‘128’

So unless all lens manufacturers can decide on a protocol to transmit unique lens names to the body, it will stay a bit messy (oh, and how to deal with manual/non-electronic lenses?)

1 Like

please dont leave this thread, I have exactly the same problem that you have (running MX-Linux 19.2, all lensfun 0.3.2-4 packages via Synaptic Package Manager). I see this problem with Nikon D850 + Nikko5 105mm 1.4 ED (which is NOT supported by lens fun). Something is not right.

I have found that lens-fun provides very few lenses compared to LR, particularly for Zeiss lenses…But, hey, this is open source world, so I will try to understand how to contribute to add my lenses to lensfun (does not seems obvious at first glance). Stay tuned

The full procedure is described in this article by Wilson Bronger.

But, does your lens need correction parameters? Prime lenses tend to show very little distortion and chromatic abberation. And for this particular lens, the only thing that seems to need correction is vignetting…

1 Like

true, depends on the lens. Zeiss is superb (modern lenses like Milvus or Otus), but vignette is very present and annoying, I want to get rid of it most of the time. For wide-angle, there is still some distortion that need to be removed (sometimes complex mustache-like type, as for Zeiss 15mm). As for the procedure, thanks, I will have a look at it. Just wonder why big companies like Zeiss dont allocate ressource to profile all of their lenses in LensFun. Specialy Zeiss, who suffered from “technical lockdown” from Nikon which refuses to release the official specs of their AF system (closed system) : they should be specially interested in OpenSource standards it seems to me

I am assuming that darktable and lensfun are correctly installed.

When I am trying to use the lenscorrection in darktable 3.2.1 for the Sony A900 I can’t select the Sony 50mm F1.4 lens.
When looking at the slr-sony.xml file of lensfun I can see that the Sony 50mm F1.4 is calibrated with a cropped camera, not a full-frame.

It is possible to convert Adobe lensprofiles using the ‘lensfun-convert-lcp’ command. This is a Python script located in ‘/usr/bin/’ in Linux. I have no idea if it gets installed in Windows.
These converted lcp-files are placed as lensfun XML-files in ‘/home/user/.local/share/lensfun’ (Linux) and automatically recognized by darktable.
More info at lensfun: Converting Adobe LCP files to Lensfun: lensfun‑convert‑lcp

When converting the Adobe file ‘SONY (Sony 50mm F1.4) - RAW.lcp’ I get the following lensfun profile:

<lens>
    <maker>Sony</maker>
    <model>Sony 50mm f/1.4</model>
    <mount>Sony Alpha</mount>
    <cropfactor>1.000907</cropfactor>
    <calibration>
        <distortion focal="50.0" model="acm" k1="-0.127915" k2="0.062124" k3="0.074677" />
        <vignetting focal="50" model="acm" aperture="2" distance="3" alpha1="-0.457701" alpha2="-18.945898" alpha3="53.020477" />
        <vignetting focal="50" model="acm" aperture="2.970854" distance="3" alpha1="-0.81574" alpha2="0.136947" alpha3="-39.9128" />
        <vignetting focal="50" model="acm" aperture="4" distance="3" alpha1="-1.648876" alpha2="16.216277" alpha3="-87.079721" />
        <vignetting focal="50" model="acm" aperture="4.970854" distance="3" alpha1="-1.32658" alpha2="5.220153" alpha3="-18.940988" />
        <vignetting focal="50" model="acm" aperture="6" distance="3" alpha1="-1.376185" alpha2="4.828291" alpha3="-13.938702" />
        <vignetting focal="50" model="acm" aperture="6.918863" distance="3" alpha1="-1.358987" alpha2="4.670938" alpha3="-13.790161" />
        <vignetting focal="50" model="acm" aperture="8.918863" distance="3" alpha1="-1.363447" alpha2="4.626719" alpha3="-14.433083" />
    </calibration>
</lens>

This new profile works together with the Sony A900 in darktable.

2 Likes

FWIW, I flew off to a photo shoot, took my laptop, but forgot the power adapter (my laptop will not run long on a fully charged battery). As a work-around, I borrowed a laptop running Windows 10 and installed the Windows version of darktable. The lens correction module worked fine, and all of my Minolta/Sony AF lenses were detected without issue. When I got home, I booted my laptop into Windows 10, installed darktable, and, in that setup, again, my lenses were correctly detected by darktable’s lens correction module.
For now, I will conduct my darktable sessions from within Windows 10. I have tried uninstalling/purging/re-installing darktable in Ubuntu. No progress in solving the problem so far. I will take a break and concentrate on editing photos.
Regards,
Caruso

Well, go figure. I am happy to report that the lens correction module is now functioning from my Ubuntu setup, go figure. I do not believe I did anything (or am unaware of what I did, if anything), but at least it is working.

Thanks for the suggestions.

Caruso

1 Like

Interesting discussion and very useful information. I use Fedora Linux, a git version of darktable and the fedora dt v4 package. I switched to the Adobe lcp directory an started the command
lensfun-convert-lcp --db-path /home/grimble/.local/share/lensfun/
but I was unsure where the lensfun database is located. So I ran the command with the db-path
/home/grimble/.local/share/lensfun/updates/version_1 and
/home/grimble/.local/share/lensfun/updates/version_2 and because I was still unsure
/usr/share/lensfun and
/var/lib/lensfun-updates

To my surprise the new lenses do not appear in the lens correction module. Do I missing something?