Beep6581 / RawTherapee

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

Dynamic Range Compression and Haze Removal - output darker than preview #4630

Open olhof opened 6 years ago

olhof commented 6 years ago

The resulting output from the queue processing invoked by ctrl-b is very much darker than the image shown in the editor.

This holds true for at least jpg output and TIFF (8 bit) output.

RT info: RawTherapee_new-shadows-highlights_5.4-249-g63f3b2f8_WinVista_64. PC info: Windows 10 version 1803

JPG outout jpg output

Screen print screen print

heckflosse commented 6 years ago

@olhof Please load the jpg in RT and post a screenshot.

olhof commented 6 years ago

Here it is...…:o)!

jpg loaded in rt

agriggio commented 6 years ago

@olhof would you be able to share the raw and pp3 perhaps?

olhof commented 6 years ago

Here is a link to the raw and pp3.

I'm very interested in the result…..:o)!

https://drive.google.com/open?id=1ARlBLY-CldysqF4J0PigxmCx4UAKy5Pb

gaaned92 commented 6 years ago

W10, last dev buid Can reproduce Rawtherapee JPG output dsc_9254

Rawtherapee preview rt-dsc_9254

heckflosse commented 6 years ago

At 100% preview it's correct.

agriggio commented 6 years ago

@olhof, like @heckflosse wrote, at 1:1 everything is fine. The culprit for the mismatch is that you are anchoring the brightness at 1% of the histogram; when working on the scaled down picture, the darkest pixels just disappear, effectively shifting the histogram to the right -- only slightly, but significantly enough in this case to make the zoomed-out preview appear much brighter. It is sufficient to raise the anchor to 5% to get a much closer match between output and (zoomed-out) preview.

gaaned92 commented 6 years ago

@agriggio @heckflosse I was not aware of that. I know that preview is in some cases ( like denoising) correct above 100% zoom. But there are warnings in GUI. In this case it seems there is no warning in the GUI and perhaps neither in the doc (I did not verified). It is not really noticeable for my night photos. But when you stumble on that, it is really disturbing.

heckflosse commented 6 years ago

@gaaned92

grafik

gaaned92 commented 6 years ago

Ah I am wrong! there was a warning.

So without Dynamic Range compression there should be no difference or negligible?

heckflosse commented 6 years ago

Yes

olhof commented 6 years ago

Thank you everyone. I see now that I get the correct image at 1:1, but I do not get any warning using the HDR-tool.

Is the last dev build W10 mentioned by gaaned92 the top one on the official download list?

gaaned92 commented 6 years ago

@olhof just on the right of the tool name, you have this small sign 1:1. It warns that the effect is only visible at 1:1 and above. Hover above it and you will get the message as in @heckflosse post. Present since official 5.4 at least. If you want use development builds see https://discuss.pixls.us/t/download-rawtherapee-development-builds/2924

Thanatomanic commented 6 years ago

Despite the warning, the Dynamic Range Compression seems like a tool that you would like to use to modify the entire image, and not locally. It's rather inconvenient then, that you cannot accurately view the result before exporting. For many other 1:1 tools, the overall result will not differ as much between preview and output (e.g. microcontrast).

olhof commented 6 years ago

I agree. In this case the difference between the preview and output is surprisingly big and not like the minor differences in sharpening, noise reduction etc.
I am sorry I overlooked the little warning “1:1” and caused a lot of work for you guys...…. But I am impressed by the responsiveness of this forum...….:o)!

ff2000 commented 6 years ago

For the new Contrast Threshold in different tools together with the sharpening contrast mask preview it makes sense to see the effect also below 1:1, even if the final result of the sharpening will be observable only at 1:1 or above.

Beep6581 commented 6 years ago

I will add @agriggio 's comment to the docs.

agriggio commented 5 years ago

Here's a patch that should improve the situation, at least in most cases. There will still be some mismatches at "extreme" settings, but avoiding that completely is not so easy. Note that the patch includes a similar fix for dehaze, which suffers from analogous problems (though unfortunately I can't find a sample image to demonstrate this right now).

diff --git a/rtengine/ipdehaze.cc b/rtengine/ipdehaze.cc
--- a/rtengine/ipdehaze.cc
+++ b/rtengine/ipdehaze.cc
@@ -36,6 +36,7 @@
 #include "procparams.h"
 #include "rt_algo.h"
 #include "rt_math.h"
+#include "rescale.h"

 extern Options options;

@@ -228,7 +229,6 @@
     array2D<float> dark(W, H);

     int patchsize = max(int(5 / scale), 2);
-    int npatches = 0;
     float ambient[3];
     array2D<float> &t_tilde = dark;
     float max_t = 0.f;
@@ -238,12 +238,27 @@
         array2D<float> G(W, H);
         array2D<float> B(W, H);
         extract_channels(img, R, G, B, patchsize, 1e-1, multiThread);
+
+        {
+            constexpr int sizecap = 200;
+            float r = float(W)/float(H);
+            int ww = r >= 1.f ? sizecap : float(sizecap) / r;
+            int hh = r >= 1.f ? float(sizecap) * r : sizecap;
+            array2D<float> RR(ww, hh);
+            array2D<float> GG(ww, hh);
+            array2D<float> BB(ww, hh);
+            rescaleNearest(R, RR, multiThread);
+            rescaleNearest(G, GG, multiThread);
+            rescaleNearest(B, BB, multiThread);
+            array2D<float> D(ww, hh);
+            rescaleNearest(dark, D, multiThread);
+
+            patchsize = 2;
+            int npatches = get_dark_channel(RR, GG, BB, D, patchsize, nullptr, false, multiThread);
+            max_t = estimate_ambient_light(RR, GG, BB, D, patchsize, npatches, ambient);
+        }

         patchsize = max(max(W, H) / 600, 2);
-        npatches = get_dark_channel(R, G, B, dark, patchsize, nullptr, false, multiThread);
-        DEBUG_DUMP(dark);
-
-        max_t = estimate_ambient_light(R, G, B, dark, patchsize, npatches, ambient);

         if (options.rtSettings.verbose) {
             std::cout << "dehaze: ambient light is "
diff --git a/rtengine/tmo_fattal02.cc b/rtengine/tmo_fattal02.cc
--- a/rtengine/tmo_fattal02.cc
+++ b/rtengine/tmo_fattal02.cc
@@ -1091,9 +1091,6 @@
         }
     }

-    float oldMedian;
-    const float percentile = float(LIM(params->fattal.anchor, 1, 100)) / 100.f;
-    findMinMaxPercentile (Yr.data(), Yr.getRows() * Yr.getCols(), percentile, oldMedian, percentile, oldMedian, multiThread);
     // median filter on the deep shadows, to avoid boosting noise
     // because w2 >= w and h2 >= h, we can use the L buffer as temporary buffer for Median_Denoise()
     int w2 = find_fast_dim (w) + 1;
@@ -1134,8 +1131,26 @@
     const float hr = float(h2) / float(h);
     const float wr = float(w2) / float(w);

-    float newMedian;
-    findMinMaxPercentile (L.data(), L.getRows() * L.getCols(), percentile, newMedian, percentile, newMedian, multiThread);
+    float oldMedian, newMedian;
+    {
+        const float percentile = float(LIM(params->fattal.anchor, 1, 100)) / 100.f;
+        float ratio = 0.f;
+        int ww, hh;
+        if (w >= h) {
+            ratio = 200.f / w;
+            ww = 200;
+            hh = ratio * h;
+        } else {
+            ratio = 200.f / h;
+            hh = 200;
+            ww = ratio * w;
+        }
+        Array2Df tmp(ww, hh);
+        rescale_nearest(Yr, tmp, multiThread);
+        findMinMaxPercentile(tmp.data(), tmp.getRows() * tmp.getCols(), percentile, oldMedian, percentile, oldMedian, multiThread);
+        rescale_nearest(L, tmp, multiThread);
+        findMinMaxPercentile(tmp.data(), tmp.getRows() * tmp.getCols(), percentile, newMedian, percentile, newMedian, multiThread);        
+    }
     const float scale = (oldMedian == 0.f || newMedian == 0.f) ? 65535.f : (oldMedian / newMedian); // avoid Nan

 #ifdef _OPENMP
heckflosse commented 5 years ago

@agriggio Alberto, compiles and works fine on Win7/64

Beep6581 commented 5 years ago

@heckflosse @agriggio please commit or push to 5.8.

Lawrence37 commented 3 years ago

Can the patch be applied for 5.9?