darktable icon indicating copy to clipboard operation
darktable copied to clipboard

Lens correction: use strength modifier for both Lensfun database & manual vignetting corrections

Open blueglyph opened this issue 7 months ago • 12 comments

Is your feature request related to a problem? Please describe. Users have expressed their need for a strength modifier in the past, like #10872 and #1990, or indirectly like #4028.

In the current lens correction module, the parameters are applied from the Lensfun database to correct the vignetting fully, without the possibility of a partial correction. As several users have already described in past feature requests or in forums, some amount of vignetting is often desired as an artistic artefact, but some lenses have too much vignetting to be left entirely uncorrected.

Describe the solution you'd like The past feature requests have unfortunately been auto-closed simply because the PR was inactive for an arbitrary number of days. I understand that there are limited resources and that they're working voluntarily, so other features have been picked first.

However, the situation has changed a little, so it's worth to revisit this issue: another feature request, #4578, asked to add support for manual vignetting correction, and a pull request, #14828, added just that. Interestingly, the lens correction module now features a strength modifier for the manual vignetting correction (and manual correction only).

A simple and elegant solution would be to use that strength control for both database-based and manual vignetting correction:

  • move the control on the UI to make it obvious it applies to both manual and database-based corrections
  • change the code to that effect, making sure the default strength is 100% if the module is first activated for a lens supported by the Lensfun database and something else (0%?) if it's not—I think that's the current default value.

I see no apparent downside. It's indeed be less probable than users should want to use both database-based and manual corrections at the same time, thus leading to a conflict of that control. Should that happen, it's always possible to add another instance of the module (which it's hard to do so to lessen the 100% correction applied by the current module).

Image

As an alternative solution, another strength control could be added for the database-based correction.

blueglyph avatar Apr 13 '25 11:04 blueglyph

The manual vignetting in darktable does not use lensfun, and a quick web search found only an on/off flag for the lensfun library's own vignetting correction. Thus it may be quite difficult to add a strength control....

ralfbrown avatar Apr 13 '25 15:04 ralfbrown

The manual vignetting in darktable does not use lensfun, and a quick web search found only an on/off flag for the lensfun library's own vignetting correction.

That indeed summarizes well what this issue suggests to improve. There's only an on/off switch, and a strength control would be much more convenient.

Thus it may be quite difficult to add a strength control....

I'm not sure I understand your argument: "it doesn't exist so it's difficult to add it"? You must have meant something else, but I don't see what. Could you please clarify?

blueglyph avatar Apr 13 '25 15:04 blueglyph

I'm not sure I understand your argument: "it doesn't exist so it's difficult to add it"?

It is currently a black box. You can turn it on or turn it off. When it's turned on the lensfun library processes the corrections and returns corrected data. That code is in the library and not part of darktable.

If the lensfun library provided a strength parameter for vignetting, then we could provide a control to adjust the strength parameter and send it to the lensfun library for processing.

So, this is really an upstream issue with the lensfun library and a feature needs to be added there to control the strength. Then we can expose it in the UI.

wpferguson avatar Apr 13 '25 18:04 wpferguson

Since it is possible to have multiple instances of Lens Correction I wonder if it would be possible to have a first instance where the user can choose to only select distortion and TCA, but then have a second instance where vignetting only was selected from the database. Then in the second instance if a uniformly mask could be appllied this would give the user control over the vignetting correction.

I can see the lack of logic for incorporating masking controls with distortion but would it be possible to provide masking control when vignetting only is being used? I see the uniformly mask as a strength parameter for any module where it is available.

tpinfold avatar Apr 14 '25 01:04 tpinfold

@tpinfold I had the same thought about using a uniform mask to control the strength when I was writing my above reply. I don't have any images that I can think of, to test this out.

wpferguson avatar Apr 14 '25 02:04 wpferguson

I thought Darktable was using its own optimized code, so I never thought it was an on/off-only call to an external lib. I have no idea what to suggest in their project since I don't know the API or even which part you're using, but the mask sounds like a possible work-around (a little more resource-intensive but perhaps more flexible).

@wpferguson Here are two raw images I recently used to create a new lens correction profile, if that's any help. They're pretty uniform, and I get quite a flat waveform when it's fully corrected, which could be useful for the tests (there's a very tiny slope, but only perceivable by doing a horizontal flip).

https://drive.google.com/file/d/1_GJJKn2b7AuXSKRtvtq4MSZqlLqQd0Vp/view https://drive.google.com/file/d/1PfhvwoShlsE8YKmJ58xBy8EzOGWvgdAj/view

The first one is at widest aperture (f/2) and focus at 27 cm (selecting 25 is fine), and it shows a lot of vignetting. The 2nd one is at f/5.6, infinity. I have twenty of them, in case you need other ones, but I may not be able to host them all (F=2, 2.8, 4, 5.6, and 16 / d=0.27, 0.54, 1.62, and inf).

The only annoyance is that you have to insert this profile since it's not released yet (darktable/share/lensfun/version_1/misc.xml). And because Darktable locks onto the LensID and ignores LensModel, you'll have to select it manually or create a .exiv2 override, but it's not a big deal.

    <lens>
        <maker>Voigtländer</maker>
        <model>35mm f/2</model>
        <model lang="en">APO-LANTHAR 35mm F2 Aspherical II</model>
        <mount>Nikon Z</mount>
        <cropfactor>1</cropfactor>
        <aspect-ratio>1.5</aspect-ratio>
        <calibration>
            <!-- Taken with Nikon Z6III -->
            <distortion model="ptlens" focal="35" a="0.00726" b="-0.01914" c="0.0101"/>
            <tca model="poly3" focal="35.0" vr="1.0000325" vb="0.9999729" />
            <vignetting model="pa" focal="35" aperture="2" distance="0.27" k1="-1.5077" k2="1.2986" k3="-0.4997"/>
            <vignetting model="pa" focal="35" aperture="2" distance="0.54" k1="-1.8845" k2="1.8993" k3="-0.7999"/>
            <vignetting model="pa" focal="35" aperture="2" distance="1.62" k1="-2.0537" k2="2.1760" k3="-0.9398"/>
            <vignetting model="pa" focal="35" aperture="2" distance="1000" k1="-2.1139" k2="2.2638" k3="-0.9802"/>
            <vignetting model="pa" focal="35" aperture="2.8" distance="0.27" k1="-0.4028" k2="-0.3614" k3="0.2385"/>
            <vignetting model="pa" focal="35" aperture="2.8" distance="0.54" k1="-0.4711" k2="-0.5282" k3="0.3748"/>
            <vignetting model="pa" focal="35" aperture="2.8" distance="1.62" k1="-0.5103" k2="-0.6242" k3="0.4640"/>
            <vignetting model="pa" focal="35" aperture="2.8" distance="1000" k1="-0.5259" k2="-0.6767" k3="0.5127"/>
            <vignetting model="pa" focal="35" aperture="4" distance="0.27" k1="-0.4734" k2="-0.0289" k3="0.0814"/>
            <vignetting model="pa" focal="35" aperture="4" distance="0.54" k1="-0.6048" k2="0.0652" k3="0.0343"/>
            <vignetting model="pa" focal="35" aperture="4" distance="1.62" k1="-0.6758" k2="0.1247" k3="-0.0003"/>
            <vignetting model="pa" focal="35" aperture="4" distance="1000" k1="-0.7045" k2="0.1404" k3="-0.0072"/>
            <vignetting model="pa" focal="35" aperture="5.6" distance="0.27" k1="-0.4665" k2="-0.0491" k3="0.0965"/>
            <vignetting model="pa" focal="35" aperture="5.6" distance="0.54" k1="-0.5809" k2="-0.0174" k3="0.1053"/>
            <vignetting model="pa" focal="35" aperture="5.6" distance="1.62" k1="-0.6463" k2="0.0142" k3="0.0997"/>
            <vignetting model="pa" focal="35" aperture="5.6" distance="1000" k1="-0.6761" k2="0.0273" k3="0.0995"/>
            <vignetting model="pa" focal="35" aperture="16" distance="0.27" k1="-0.4873" k2="-0.0271" k3="0.0859"/>
            <vignetting model="pa" focal="35" aperture="16" distance="0.54" k1="-0.5879" k2="-0.0363" k3="0.1203"/>
            <vignetting model="pa" focal="35" aperture="16" distance="1.62" k1="-0.6509" k2="-0.0147" k3="0.1216"/>
            <vignetting model="pa" focal="35" aperture="16" distance="1000" k1="-0.6799" k2="-0.0177" k3="0.1383"/>
         </calibration>
    </lens>

1st image, without and with correction:

Image Image

2nd image

Image Image

blueglyph avatar Apr 14 '25 07:04 blueglyph

Thanks for suggesting that approach, by the way. 🙂

blueglyph avatar Apr 14 '25 07:04 blueglyph

I agree that vignetting strength should be controllable, it would be great to have the option to have a mask on the second instance of lens correction

shanecranor avatar May 02 '25 20:05 shanecranor

It's a one-line change to enable masking (add IOP_FLAGS_SUPPORTS_BLENDING to function flags()), though you'll have problems if distortion or TCA are enabled on the same instance for which masking is enabled. With either of those, it's possible for the input and output of the module to differ slightly in resolution and cause the blending to be skipped.

ralfbrown avatar May 05 '25 13:05 ralfbrown

@wpferguson Were the images helpful? Let me know when I can take them down.

blueglyph avatar May 05 '25 13:05 blueglyph

@wpferguson I couldn't get any answer from you, unfortunately. I'll take the files down, as I need the space for something else.

blueglyph avatar Jun 25 '25 11:06 blueglyph

I couldn't get any answer from you,

My apologies. I somehow missed this.

wpferguson avatar Jun 26 '25 00:06 wpferguson

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

github-actions[bot] avatar Aug 26 '25 00:08 github-actions[bot]

I suppose I have to comment so that this doesn't close automatically...

blueglyph avatar Aug 26 '25 07:08 blueglyph

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

github-actions[bot] avatar Oct 26 '25 00:10 github-actions[bot]

I suppose I have to comment so that this doesn't close automatically...

blueglyph avatar Oct 26 '25 08:10 blueglyph