Beep6581 / RawTherapee

A powerful cross-platform raw photo processing program
https://rawtherapee.com
GNU General Public License v3.0
2.89k stars 323 forks source link

Color artifacts when using lensfun geometric distortion correction #5425

Open KaruroChori opened 5 years ago

KaruroChori commented 5 years ago

Versions affected: 5.4, 5.5, 5.6 OS.: 4.15.0-50-generic #54-Ubuntu SMP Mon May 6 18:46:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux When a correction profile for the geometry is applied to any raw file (from a fujifilm x-t1) some of the pixels become much more saturated ruining the quality of the final image. Often the effect is even worse than what is shown in the screenshot I attached. Screenshot from 2019-08-24 17-49-01

sguyader commented 5 years ago

Hi, No idea really of the cause of solution, but can you try to tick the "chromatic aberration" box, and also in the demosaicing options, add 1 step of false color correction? Maybe the lensfun profile isn't great for this lens. But do you really need to correct for distortion on this lens?

KaruroChori commented 5 years ago

Ticking the chromatic aberration box does not have any kind of effect. I tried with many different values for the correction of false colours but still, this does only mitigate a problem which is introduced while applying a distortion correction, it was not there in the original raw file, and when developed with other programs it just works flawlessly. It is not about the specific lens profile. When using a manual correction the problem is still there even for the smallest correction applicable. If I have to guess I would say it is a bug in the interpolation algorithm which is used. This is not the point, a flaw is a flaw, and it seems not to be specifically related to this lens :).

heckflosse commented 5 years ago

@KaruroChori http://rawpedia.rawtherapee.com/How_to_write_useful_bug_reports

Especially: Upload the raw + PP3. Make your raw and PP3 files available to us by uploading them to a file sharing service such as www.filebin.net if your bug involves a particular raw file, a particular setting, or lack of support for your raw file

KaruroChori commented 5 years ago

https://filebin.net/hdj4okrt8x054n0x

Thanatomanic commented 5 years ago

I can confirm the effect, and it's also visible to a lesser extent in area's without extremely blown out highlights. Not sure it's a bug though...

Thanatomanic commented 5 years ago

@KaruroChori

Ticking the chromatic aberration box does not have any kind of effect.

This is because the lens profile does not contain CA correction. See http://lensfun.sourceforge.net/lenslist/

KaruroChori commented 5 years ago

@Thanatomanic

This is because the lens profile does not contain CA correction. See http://lensfun.sourceforge.net/lenslist/

Sure, it was just to answer @sguyader who was wondering if selecting that option had any effect.

heckflosse commented 5 years ago

Maybe we should gray out the CA correction checkbox in lens profile tool if the lens profile does not contain CA correction ...

sguyader commented 5 years ago

@Thanatomatic that's not true, according to the lensfun table, the lens (27mm f/2.8) profile does provide TCA correction: TCA is in the second column of the table, not the third one.

Thanatomanic commented 5 years ago

@sguyader You are absolutely right, sorry about that. The list is probably outdated, because in mil-fujifilm.xml in the lensfun database on my system it says the following:

    <lens>
        <maker>Fujifilm</maker>
        <model>XF27mmF2.8</model>
        <model lang="en">XF 27mm f/2.8</model>
        <mount>Fujifilm X</mount>
        <cropfactor>1.529</cropfactor>
        <calibration>
            <!-- Taken with X-A1 -->
            <distortion model="poly3" focal="27" k1="-0.00621"/>
            <tca model="poly3" focal="27" vr="0.999996" vb="1.00002"/>
            <!-- Taken with Fujifilm X-T1 -->
            <vignetting model="pa" focal="27" aperture="2.8" distance="10" k1="-0.9412" k2="0.1158" k3="0.1433"/>
            <vignetting model="pa" focal="27" aperture="2.8" distance="1000" k1="-0.9412" k2="0.1158" k3="0.1433"/>
            <vignetting model="pa" focal="27" aperture="4" distance="10" k1="-0.3815" k2="-0.0002" k3="-0.0924"/>
            <vignetting model="pa" focal="27" aperture="4" distance="1000" k1="-0.3815" k2="-0.0002" k3="-0.0924"/>
            <vignetting model="pa" focal="27" aperture="5.6" distance="10" k1="-0.5174" k2="0.4132" k3="-0.2336"/>
            <vignetting model="pa" focal="27" aperture="5.6" distance="1000" k1="-0.5174" k2="0.4132" k3="-0.2336"/>
            <vignetting model="pa" focal="27" aperture="8" distance="10" k1="-0.4814" k2="0.2629" k3="-0.0925"/>
            <vignetting model="pa" focal="27" aperture="8" distance="1000" k1="-0.4814" k2="0.2629" k3="-0.0925"/>
            <vignetting model="pa" focal="27" aperture="11" distance="10" k1="-0.4844" k2="0.2659" k3="-0.0926"/>
            <vignetting model="pa" focal="27" aperture="11" distance="1000" k1="-0.4844" k2="0.2659" k3="-0.0926"/>
            <vignetting model="pa" focal="27" aperture="16" distance="10" k1="-0.4938" k2="0.2759" k3="-0.0978"/>
            <vignetting model="pa" focal="27" aperture="16" distance="1000" k1="-0.4938" k2="0.2759" k3="-0.0978"/>
        </calibration>
    </lens>

So all three of them are there, but I suppose the TCA is so minor you don't notice it.

heckflosse commented 5 years ago

Using A = -0.5; here https://github.com/Beep6581/RawTherapee/blob/dev/rtengine/improcfun.h#L82 improves the result...

KaruroChori commented 5 years ago

As far as I know overshooting, and as a consequence ending up with a clipped signal, is intrinsic in a bicubic interpolation. Letting the user chose A may mitigate the problem, at the expense of what I think would be the perceived sharpness after the transformation. In general having more interpolation algorithms from which to choose could be helpful.

heckflosse commented 5 years ago

@KaruroChori

Letting the user chose A may mitigate the problem, at the expense of what I think would be the perceived sharpness after the transformation.

I didn't intend to let the user chose A. That was just a try to improve the result as A = -0.85 is uncommon. Let's keep the interface simple and find a better solution...

heckflosse commented 5 years ago

@KaruroChori Additionally, while I worked on this issue, I made a speedup for the transformation (while keeping A and also the artifacts). Now the transformation takes 550 ms on my machine for a Nikon D800 file while before it took 660 ms. This will not go into 5.7, but most likely into 5.8.

TooWaBoo commented 5 years ago

@heckflosse

Maybe we should gray out the CA correction checkbox in lens profile tool if the lens profile does not contain CA correction ...

It does.