Create lens calibration data for lensfun

A rope like that would have some sag, which would look like pincushion distortion, and this would result in overcorrection.

What about something like that https://images.app.goo.gl/1Lm61QXavBP6nN5h6 ? Does that enough ?

I tried, but while hugin removes the distortion perfectly in the panorama preview, lensfun still has some: hugin panorama preview calibrates perfectly, lensfun still has distortion · Issue #1360 · lensfun/lensfun · GitHub No replies there… Who can I ask about this?

Any idea why that might happen? I have zero idea how to proceed from here, but need to undistort sort of urgently now. :frowning:

I wonder if there is any maintainer that I can ping… my pull request has been sitting there for nearly 2 years and I cannot fathom why it would not be merged.

Also, as mentioned in the PR, I was working on fully automatic distortion correction (automatically detecting contours and then using Nelder-Mead simplex optimization to solve for calibration parameters) but I abandoned working on that since it seemed that nobody cared.

Not really, lensfun needs a dedicated maintainer. Not sure if @junkyardsparkle can help or not.

1 Like

For tca correction I found a grey metal fence with white background to be really good.

uncorrected
Uncorrected

corrected-version1
Source motive for tca correction was what I think this one.

corrected-version2
Fence as a source sample.

3 Likes

For vignetting we run the script with the following folder structure:

vignetting/0.8
vignetting/1.6
vignetting/4.8
vignetting/inf

Is it for zoom lenses possible to have:

vignetting/70mm/0.8
vignetting/70mm/1.6
vignetting/70mm/4.8
vignetting 70mm/inf

vignetting/90mm/0.8
vignetting/90mm/1.6
vignetting/90mm/4.8
vignetting 90mm/inf

If that’s a question, I think that’s how I did it and it worked fine

It was a question until I tried 5 minutes ago ^^

1 Like

no xml file for my nikon 80-400 AF-S so I copied one provided by augustlej on github/lensfun to the described
~/.local/share/lensfun

this is an incorrect location. it actually should be:
~/.local/share/lensfun/lensfun.xml

and it works as expected.

With Nikon D850 and the like there are different options.
This refers to Create lens calibration data for lensfun - #66 by bilddateien

  1. I use a telephoto lens as is - and the full sensor size
  2. I use a telephoto lens as is - and use in-camera cropping to 30x20 (1.2x) or 24x16 (APS, 1.5x)
  3. I use a telephoto lens - but with teleconverter - and the full sensor size
  4. I use a combination of the previous two cases

With regard to vignetting in particular:
For cases

  1. no problem with that - just proceed as documented
  2. this is an open question for me: is lensfun smart enough to see the “in-camera-crop factor”?
    I don’t think so since there is a camera section
    <camera>
        <maker>Nikon Corporation</maker>
        <maker lang="en">Nikon</maker>
        <model>Nikon D850</model>
        <model lang="en">D850</model>
        <mount>Nikon F AF</mount>
        <cropfactor>1</cropfactor>
    </camera>
    
    and a lens section
    <lens>
        <maker>Nikon</maker>
        <model>Nikon AF-S Nikkor 500mm f/5.6E PF ED VR</model>
        <mount>Nikon F AF</mount>
        <cropfactor>1.0</cropfactor>
        <calibration>
            <!-- Taken with Nikon D850 -->
            <vignetting model="pa" focal="500" aperture="5.6" distance="10" k1="-0.9794" k2="1.0007" k3="-0.4530"/>
            (...)
        </calibration>
    </lens> 
    
    both of which do not show any possibility for handling this scenario - I don’t think it would be a good idea simply to have multiple camera entries with different crop factors (?)
  3. found the answer here: On Lens Detection and Correction | darktable

    A lens+teleconverter combination is treated as a lens of its own. It needs its own calibration, and its own entry in the lens list. One can not combine two calibrations in any way.

  4. depends on the previous two cases

Why is this case 2 important?

depends on the lens and the character of the vignetting. Hard vignetting in the corners - ok, you are right. But with gradual vignetting as in this example

even when cropping to APS the effect of correction is clearly visible.

The distortion correction method currently described in this article only gives you 3 digits after the decimal point for each parameter, which is a bit short. It was pointed out to me (see here) that there is a better method to copy the distortion parameters, which preserves all the digits. Could the article be updated to mention the alternative method?

I am trying to measure only the vignetting data, for a Canon RF lens (Canon RF 24-105mm F4L IS USM; distortion and TCA are already covered in lensfun). Raw files are therefore .CR3 files.

When I launch ./lens_calibrate.py vignetting I have a message saying that Exif.Photo.FocalLength and Exif.Photo.FNumber aren’t set and I should fix it manually. Same for Exif.Photo.LensModel since the lens_model in the script end up with the value ‘Standard’ (line 359).

But I don’t know where I should fix it manually. And exiv2 is able to read FNumber or FocalLength:

$ exiv2 -pa -g FNumber -g Exif.Photo.FocalLength vignetting/24mm.cr3
Exif.Photo.FNumber                           Rational    1  F8
Exif.Photo.FocalLength                       Rational    1  24.0 mm

Is someone able to help? Thanks!

Additionnal context:

  • Linux Mint 20.3, darktable 4.0, exiv2 0.27.5
  • I changed the lens_calibrate.py script by adding “.CR3” in the function is_raw_file(filename) (line 312). But maybe it’s not enough to do just that…!

Converting to dng should work also.

Indeed, it works without any problem with dng! Thanks :slight_smile:

Hello,

about geometric distortion calibration, why not using tools like example codes from OpenCV lib and checkerboard pattern?
From my point of view it seems easier than using Hugin.
links:
https://docs.opencv.org/4.6.0/d9/d0c/group__calib3d.html
https://docs.opencv.org/4.6.0/d4/d94/tutorial_camera_calibration.html

I can explore more on this if your are not opposed tu such procedure.

Best

How do you deal with focus distance? Different focus point, different distortion.

This method above seems similar to the one you do when you create a profile for Adobe.

Right, thanks to remind this point.
If the idea is to measure when focus is close to infinite then it is harder with such target.

I migth try anyway to see the feasability, and to compare if targets can be detected from long distances (small checkers, or try circles patterns)

in the end it’s just about how to determine the parameters lensfun needs. No one cares how these were calculated if they are correct :wink: so feel free to use different methods…

When I have taken all raw samples for vignetting, I run
exiftool -d %Y_%m_%d '-filename<$FocalLength/$FocusDistanceUpper/%f.%e' .

Skärmbild från 2023-04-12 10-39-38

How should I write in Terminal to not get m and mm?

And this one is not a question but something I find helpful for Canon cameras with Magic Lantern. I use it with my 6D. A lua script to load in the camera to take the raw samples fast. This script takes a sample from f/3.5 at every aperture until f/16. Then it jumps to the last one at f/45.

-- f3.5
function test()

    camera.aperture.value = 3.5
    camera.shoot()
    camera.aperture.value = 4.0
    camera.shoot()
    camera.aperture.value = 4.5
    camera.shoot()
    camera.aperture.value = 4.9
    camera.shoot()
    camera.aperture.value = 5.6
    camera.shoot()
    camera.aperture.value = 6.4
    camera.shoot()
    camera.aperture.value = 7.0
    camera.shoot()
    camera.aperture.value = 8.0
    camera.shoot()
    camera.aperture.value = 9.1
    camera.shoot()
    camera.aperture.value = 9.9
    camera.shoot()
    camera.aperture.value = 11
    camera.shoot()
    camera.aperture.value = 13
    camera.shoot()
    camera.aperture.value = 14
    camera.shoot()
    camera.aperture.value = 16
    camera.shoot()
    camera.aperture.value = 45
    camera.shoot()
end

keymenu = menu.new
{
    name = "f/3.5",
    select = function(this) task.create(test) end,
}