Lens calibration data (lensfun, version 1) are not recognized by DT 4.0 automatically

The ~/.exiv2 file already mentioned can tell dt the correct information to pass to lensfun.

True, but only if there is a numerical LensID/LensType to perform the mapping.

The OP still hasn’t shown all the relevant Exif and MakerNote data.

I believe this would function. I am Windows user and DT runs under Windows. I could not find any reliable information what should be the contents of that file and where to locate in Windows system.

I attached a RAW file taken with Fujifilm X-S10 with attached Viltrox 85 mm lens. You can get all the information out of it.
_DSF3267.RAF (25.2 MB)

So the Fujifilm MakerNote doesn’t include the LensID/LensType numerical tag like e.g. Canon or Nikon do, so not sure how the exiv2.ini mapping would work in this case. I’ll have to take a closer look at the exiv2 and dt code when I find some time…

Thank you for your interest in trying to help me. It is not urgent. I think the key point is how DT handles the lensfun database.

I think DT should use the lens corrections embedded in metadata.

Has someone reverse engineered and posted how that metadata works?

Perhaps @agriggio ?

Sorry, what is the question exactly?

Have you reverse engineered and implemented lens correction where the correction data stored in the raw file is used?

Yep, Fujifilm MakerNotes are not bypassed by exiv2.ini (like Minolta, Olympus, Nikon, Canon, etc), so that route is a dead end.

So have to think on the dt side how to improve the detection for Fujifilm cameras. Blindly using LensMaker + LensModel might break currently working things…

What’s interesting is that there is a lensfun crop entry for another Viltrox on the X-mount, which indeed also does not have the “Viltrox” prefix, so they will likely accept another entry like that (the existing one for the full crop and including the prefix being unsuitable and therefore completely different), so this is probably the best bet.

Hi,

Not really. But someone else did, at least in part. There was an announcement here some time ago (1-2 years already maybe?) and an associated pr for darktable, that supported Fuji and Sony cameras. I integrated it into art and extended also to dng files (also not reverse engineered, just taken from the dng spec and adapted from the lcp implementation already available in rawtherapee). IIRC someone else also figured out part of the corrections for Panasonic cameras (or possibly even all m43 cameras), but I haven’t looked into that yet.

Messed around with /src/iop/lens.cc in darktable for 4 hours, just to find out, as someone mentioned, it’s a lensfun problem parsing and matching the lens name. It’s this lensfun function:

FindLenses (const lfCamera *camera, const char *maker, const char *model, int sflags=0)

Specifically it’s having problem with “85/1.8”. If I replace that part by “85 1.8” in both the EXIF of the image, and in the lensfun’s XML file, then darktable/lensfun would have no problem autodetecting the lens.

Here is a JPG with the “Lens Model” in EXIF has been modified to “AF 85 1.8 II XF”.

Here’s the viltrox_85.xml I’m using that would work with the above JPG. The vignetting data is made-up just for testing.

<lensdatabase version="1">
  <lens>
    <maker>Viltrox</maker>
    <model>AF 85 1.8 II XF</model>
    <mount>Fujifilm X</mount>
    <cropfactor>1.53</cropfactor>
    <calibration>
      <distortion model="ptlens" focal="85" a="0" b="0.00846" c="0"/>
      <vignetting model="pa" focal="85.0" aperture="2.5" distance="10" k1="-0.5485433" k2="0.6021258" k3="-0.6310329" />
      <tca model="poly3" focal="85" vr="0.9998219" vb="0.9999488"/>
    </calibration>
  </lens>
</lensdatabase>

Also found out that darktable doesn’t read the lens maker from EXIF (VILTROX), and thus doesn’t pass it to lensfun for searching. I tried passing the lens maker to lensfun’s FindLenses() but that didn’t help. Adding “Viltrox” into the Lens Model didn’t help neither. So, nothing needs to be done to darktable in this case.

One work-around for now is to select the lens manually, apply the default correction or none, then save it as a preset that automatically applied to the matching lens model. That way, the correct lens profile will be automatically pre-selected upon importing the image into darktable.

It’d be nice if OP can submit a bug report to lensfun. Otherwise, I can do that sometime later. I’m using lensfun 0.3.3.

That’s right, adding the correct/expected model for the Fuji body is the only thing to do here. The way the lens string is read and generated on the Nikon body is completely different. Welcome to the world of non-standardized and very fragmented lens recognition.

Thank you very much. I edited <model> data accordingly - just replaced “/” by a blank - and then after applying lens correction manually I defined a preset as shown by your screenshot, it worked. You left at the preset lens correction module the character % for the lens specification. % is the wild character specification, I believe. Instead, I started lens name with two blanks. It works, too.

I understand the main issue is that lens identification does not work for foreign lenses for the Fujifilm X mount. Fuji lenses are identified correctly.

Surely, I will submit a bug report to lensfun. Thanks again.

Again, this not a lensfun bug per se. Just the consequence of the wonderfully fragmented world of lens metadata.

You didn’t have to replace the / by space, that was just to pin-point the autodetection problem. In this case, in order to get autodetection to work, the space replacement has to happen in both EXIF and the XML. But, it doesn’t matter with the forced auto-preset, so you can leave your modification in there :slight_smile:

Yeah, I didn’t test if darktable would trim the leading space, so I was being lazy by leaving the wildcard in front. Yours work, too, as it matches the lens model from EXIF exactly. :+1:

It’s not that lens identification does not work for foreign lenses, it’s the chaos of lens naming from the manufacturers, especially smaller Japanese players. My Tamron “17-70mm F/2.8 DiIII-A VC RXD B070X” has no problem being autodetected. The majority players (Nikon, Canon, …) follows the same syntax: [minFL-maxFL]mm F/[maxAperture], even primes such as “XF 56mm f/1.2 R APD”. You can see how the / is typically used just for aperture, not in a FL/A combo.

I guess Viltrox doesn’t pay attention to the industry and not playing along in the naming scheme. Lensfun’s parsing algorithm is mostly trial-and-error from the long list of non-uniform lens models, and thus didn’t cover these outliers. It could be tweaked better, but will also involve a lot of regression tests to make sure that the tweak doesn’t break what has been working.

thanks!

Here is another photo taken with an Viltrox 85mm f/1.8 Z lens on a Nikon Z5. The Exif data provide the lens model “Viltrox AF 85/1.8 Z”. The automatic image recognition with Darktable also failed with this image. But the comparison with RawTherapee is interesting.
In any case, the slash, as used in the Exif data of the Viltrox XF, is a problem (see also this description).

Picture_1 taken with Viltrox 85mm f/1.8 Z on Nikon Z5.

Viltrox_AF_85__1.8_Z--085mm--1.8_Nikon_Z5

$ exiv2 -pt Viltrox_AF_85__1.8_Z--085mm--1.8_Nikon_Z5.jpg | grep -i lens  
Exif.Nikon3.LensType                         Byte        1  (0)
Exif.Nikon3.Lens                             Rational    4  85mm F1.8
Exif.Nikon3.LensFStops                       Undefined   4  6.33333
Exif.Nikon3.LensData                         Undefined 108  48 56 48 49 166 117 115 160 252 135 65 42 66 137 255 164 120 123 173 14 158 93 75 104 180 47 217 178 ...
Exif.Photo.LensSpecification                 Rational    4  850/10 850/10 180/100 180/100
Exif.Photo.LensMake                          Ascii       6  
Exif.Photo.LensModel                         Ascii      65  Viltrox AF 85/1.8 Z
Exif.Photo.LensSerialNumber                  Ascii      11  0  

lensfun profile in misc.xml:

    <lens>
        <maker>Viltrox</maker>
        <model>Viltrox AF 85mm f/1.8 Z</model>
        <mount>Nikon Z</mount>
        <cropfactor>1</cropfactor>
        <calibration>
            <!-- Taken with Nikon Z 6 -->
            <distortion model="ptlens" focal="85" a="0" b="0.00846" c="0"/>
            <tca model="poly3" focal="85" vr="0.9998219" vb="0.9999488"/>
        </calibration>
    </lens>

Automatic lens detection in Darktable → no
Automatic lens detection in RawTherapee → yes
#########
model in lensfun misc.xml changed to what exiv2 reports:

 <model>Viltrox AF 85/1.8 Z</model>

Automatic lens detection in Darktable → no
Automatic lens detection in RawTherapee → no

#########

Picture_2 taken with Viltrox 85mm f/1.8 II XF on Fujifilm X-S10.

Viltrox_AF_85__1.8_II_XF_Fujifilm_x-S10

$ exiv2 -pt Viltrox_AF_85__1.8_II_XF_Fujifilm_x-S10.jpg | grep -i lens
Exif.Photo.LensSpecification                 Rational    4  8500/100 8500/100 180/100 180/100
Exif.Photo.LensMake                          Ascii      13  VILTROX 
Exif.Photo.LensModel                         Ascii      64    AF 85/1.8 II XF
Exif.Photo.LensSerialNumber                  Ascii      11  00000002

lensfun profile in misc.xml:

<lens>
        <maker>Viltrox</maker>
        <model>AF 85mm f/1.8 II XF</model>
        <mount>Fujifilm X</mount>
        <cropfactor>1.53</cropfactor>
        <calibration>
            <!-- Taken with Nikon Z 6 -->
            <distortion model="ptlens" focal="85" a="0" b="0.00846" c="0"/>
            <tca model="poly3" focal="85" vr="0.9998219" vb="0.9999488"/>
        </calibration>
    </lens>

Automatic lens detection in Darktable → no
Automatic lens detection in RawTherapee → no
#######
model in lensfun misc.xml changed to what exiv2 reports:

<model>AF 85/1.8 II XF</model>

Automatic lens detection in Darktable → no
Automatic lens detection in RawTherapee → no

#########

Picture_3 with Viltrox 85mm f/1.8 II XF on Fujifilm X-S10 with modified exif data.

changed-exif_Viltrox_AF_85__1.8_II_XF_Fujifilm_X-S10

$ exiv2 -pt changed-exif_Viltrox_AF_85__1.8_II_XF_Fujifilm_X-S10.jpeg | grep -i lens
Exif.Photo.LensSpecification                 Rational    4  85/1 85/1 9/5 9/5
Exif.Photo.LensMake                          Ascii       9  VILTROX 
Exif.Photo.LensModel                         Ascii      17  AF 85 1.8 II XF

Exif.Photo.LensSerialNumber                  Ascii       9  00000002
  <lens>
        <maker>Viltrox</maker>
        <model>AF 85mm f/1.8 II XF</model>
        <mount>Fujifilm X</mount>
        <cropfactor>1.53</cropfactor>
        <calibration>
            <!-- Taken with Nikon Z 6 -->
            <distortion model="ptlens" focal="85" a="0" b="0.00846" c="0"/>
            <tca model="poly3" focal="85" vr="0.9998219" vb="0.9999488"/>
        </calibration>
    </lens>

Automatic lens detection in Darktable → yes
Automatic lens detection in RawTherapee → yes
########
model in lensfun misc.xml changed to what exiv2 reports:

<model>AF 85 1.8 II XF</model>

Automatic lens detection in Darktable → yes
Automatic lens detection in RawTherapee → yes