Beep6581 / RawTherapee

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

Choice of curve scales: gamma-corrected, logarithmic, other #2644

Open Beep6581 opened 9 years ago

Beep6581 commented 9 years ago

Originally reported on Google Code with ID 2661

Related: issue 2659.

In short: curves applied to RAW files are not uniform in that you cannot make adjustment
equal to N EV with just two points. You cannot threat different tonal ranges equally
and expect equal look.

Their behaviour is similar to curves of Photoshop which are not uniform too (and Exposure
slider of Photoshop does not really adjusts exposure but gamma-corrected exposure instead
and this is not documented).

I call them gamma-corrected because they are applied to gamma-corrected data.

There are two "uniform" alternatives to current curves: linear curves and logarithmic
curves (I called them exponential before).

Here is a brief example of how they work: http://imgur.com/a/MZ0AF

Linear curves give each half of the window to the very last stop of tone range. It
means that if you want to manipulate the shadows which are 8 stops below the white
point you will need to use 2^8=256 times narrower area which is 256^2 smaller than
all area. Midtones are 4 stops below white point, and you have 2^4=16 times narrower
area for them.

Linear curves are somewhat less efficient than gamma-corrected curves but only a bit
(you may see this in screenshot album).

Logarithmic curves are very different: they give each stop of tonal range equal area.
It is generally easier to get naturally looking image with them. They are also super-handy
for files with huge DR like 100 shots averaged.

Both of these "uniform" curves modes does not have equal straight curve for straight
curve from another mode, they are not universally uniform against each other.

It was said that logarithmic curves give less control if highlights. No prob here,
Custom tone curve 1 may be logarithmic and other one may be linear or vise versa.

It is also worth to say that this feature will be unique across wide range of products
if it is implemented. The only place where I have seen logarithmic curve was Photoshop's
HDRPro plugin but it was not pure tone curve.

I think that "logarithmic" should be a checkbox so it is possible to combine it with
"weithed: and :satval blending".

I also have and idea of what could be done to make logarithmic curves all-in-one alternative
to what RT has now - the highest stops of it can be wider. If the grid of curves windows
corresponds with this non-uniformity the predictability of tone shift won't be heavily
compromised.

This is v2 prealpha patch for 4.2.0. It:
0) does not follow core design guidelines and does not provide any kind of compatibility
with existing pp3 (output is very different) but it also does not compromise image
quality so it is almost ready to use;
1) makes curves perfectly linear;
2) makes optional logarithmic mode, separately switched for 1, 2 and RGB curves;
3) makes grid of curves window to have "number of stops" cells if logarithmic curves
are enabled.

DrSlony said that there were some errors being output to console when he used v1 patch.
I do not address it because I have no clue. I altered win.cmake for myself, this is
not included in patch now.

Make tcSettings file in RT root.

In tcSettings "1 1 1 14" means "enable logarithmic tonecurve 1" "enable logarithmic
tonecurve 2" "enable logarithmic RGB curve" "14 tone stops of curves window". "0 0
0 14" means "all linear".

If assignment of "%d%d%d%lf" in fscanf fails, it reverts back to linear curves.

14 stops is overkill for most tasks, yo may use 10 or even 8. If you want to make accurate
highlight adjusments disable logarithmic scale of tone curve 2 and use it for that.

It came out not so short.

Reported by pinhuer on 2015-02-09 15:21:58


Beep6581 commented 9 years ago
>You cannot TREAT different tonal ranges equally and expect equal look.

>I think that "logarithmic" should be a checkbox so it is possible to combine it with
"weighted" and "satval blending".

Reported by pinhuer on 2015-02-09 15:31:55

Beep6581 commented 9 years ago
For accurate highlights adjustments write "1 0 1 14" to tcSettings file and use Tone
Cruve 2.

Also: if you change the number of stops from 14 to another you will get different output
with same PP3.

Reported by pinhuer on 2015-02-09 15:39:03

Beep6581 commented 9 years ago
I am mixing the use of "scale" and "mode" but I should always use "scale" in discussing
of all related issues. Modes are "blending", "weighted" and "standard", scales are
"gamma-corrected", "linear", "logarithmic".

Issue should be called "Curve scale which is ...".

Reported by pinhuer on 2015-02-09 15:41:17

Beep6581 commented 9 years ago
Quick paste from IRC of a test of patch 1:

neutral http://i.imgur.com/wz8oe1Y.jpg                                            

-2EV EC http://i.imgur.com/jTZxCko.jpg                                            

-2EV TC http://i.imgur.com/dGqpiv1.jpg                                            

+2EV EC http://i.imgur.com/astZ5U6.jpg                                            

+2EV TC http://i.imgur.com/Kwj3BvR.jpg                                            

current RT curve: http://i.imgur.com/rlKIFB3.jpg                                  

log curve http://i.imgur.com/ZYNN7BZ.jpg                                          

current http://i.imgur.com/xwQuzbA.jpg                                            

log curve http://i.imgur.com/WxeaPig.jpg                                          

current RT curve http://i.imgur.com/QCJFkPx.jpg                                   

log curve http://i.imgur.com/IdxqGey.jpg                                          

It would be interesting to mix the log curve for shadow control with a normal curve
for highlight control.

Issues to be addressed for such a patch to be committed:
1- The feature should not use these tcSettings files. Each curve would need to get
a combobox for the scale (assuming current curves are gamma-corrected): gamma, log,
linear, etc.
2- Optionally, if useful, a combobox or inputbox should be implemented for the grid.
3- All these settings would need to be read/written to the PP3.
4- The internal PP3 version should be bumped. If no curve mode is present in the PP3
(old PP3s), RT should assume the curve uses the currently implemented scale (gamma?).
5- The curve histogram should reflect the data flowing into the curve if it is changed
by the patch.
6- The gradients of the X and Y bars may need to be updated too.

Issues with patch 1:
- Plenty of these in the console: OVERFLOW: hash #65529 is used while seeking for value
-0.07142700
- RT segfaults during startup if the tcSettings file is not present
- RT must be run from within its folder. e.g. if I have RT in /home/entertheyoni/rt_default_release_2661log1
and I am in /home/entertheyoni/ and I try to run ~/rt_default_release_2661log1/rawtherapee
it will fail, I must first cd to ~/rt_default_release_2661log1/ and then run ./rawtherapee
  Of course this will be obsolete once the curve scale is read to/from PP3.

Pinhuer you can find these test images in http://rawtherapee.com/shared/test_images

Reported by entertheyoni on 2015-02-09 15:48:01

Beep6581 commented 9 years ago
Let me clarify some things in my mind.

The current curves are log2.2, the new log curve is log2.0 (fully compatible with photographic
stops), the linear in log1.0 correct ?. 

Reported by iliasgiarimis on 2015-02-09 16:29:58

Beep6581 commented 9 years ago
>The current curves are log2.2, the new log curve is log2.0 (fully compatible with photographic
stops), the linear in log1.0 correct ?. 

No.

Power function is a power function. In terms of functions of smaller order they are
"root2.2(X)" (but I have not verified it, need to dig into rawimagesource.cc, it may
be different from 2.2). I am also suspecting that they should be called "power" so
I call them gamma-corrected instead. It is also worth to note that you cannot easily
make inverse tone curve for a given gamma-corrected curve.

Linear is not log1 because log1(X) is not defined for any X!=1. Linear is just X.

The new curve is log2(X), but you can call it just log(x) because logY(X)/logZ(X)=const
so the base does not matter, it only matters for drawing the grid behind the curves.

I am sorry for using too much terms but I do not want to sacrifice the accuracy of
my statements.

Reported by pinhuer on 2015-02-09 16:51:07

Beep6581 commented 9 years ago
Ahh .. yes .. I mixed log with gamma 2.2 .. 2.0 .. 1.0 :(

Reported by iliasgiarimis on 2015-02-09 17:47:56

Beep6581 commented 9 years ago
There is also a different approach: X-axis can be logarithmic and Y axis can be linear.

Reported by pinhuer on 2015-02-09 18:47:15

Beep6581 commented 9 years ago
BTW: it becomes much easier to use the color propagation in highlights with logarithmic
curves - you switch on propagation, do -1EV correction and then use the same curve
which you use without propagation just with 1 EV shoulder.

Reported by pinhuer on 2015-02-21 20:49:21

Beep6581 commented 9 years ago
A question: how do I access linear image data after iGamma in improcfun?

Reported by pinhuer on 2015-03-29 20:28:59

Beep6581 commented 9 years ago
pinhuer, I have a patch in issue 2593 that update the files of the Curve Editor. If
it collide your patch, let me know on how to proceed.

Reported by natureh.510 on 2015-04-03 21:00:49

Beep6581 commented 9 years ago
Started by Pinhuer.

Reported by entertheyoni on 2015-04-04 18:37:02

Beep6581 commented 9 years ago
Usage of gamma in curves.cc:complexCurve? What for?

I am now digging into the tone curves mechanism and, for convinience, I want to separate
the calculation of LUT from the curves scaling.

There is usage of Gamma in said function and it is clearly interesting for me to know
what is it really for. As I said in https://code.google.com/p/rawtherapee/issues/detail?id=2730#c7,
there is gamma in improcfun exclusively for providing the common behavior of curves,
and I struggle to understand why gamma is used in curves.cc .

Reported by pinhuer on 2015-04-05 14:25:55

Beep6581 commented 9 years ago
Gamma in complexCurve is probably related to highlights.

I really need some advisory on this.

Please Cc natureh and heckflosse, they seem to have edited lines dealing with gamma
and may provide some support.

Reported by pinhuer on 2015-04-05 14:33:13

Beep6581 commented 9 years ago
I'm already surveying.this issue, but I don't know why and when the gamma is used, that's
not my part of.the code, sorry. Almost all legacy dev have left, so I don't know who
can help you, maybe Jacques (jdesmis) or Ingo (heckflosse).

Reported by natureh.510 on 2015-04-05 18:28:23

Beep6581 commented 9 years ago
There is no version information included in RTC files. Is there an aspect of it which
is important?

I am tending towards including gamma-corrections and scaling inside of curves.cc exclusively
and passing scaling parameters in arguments.

Reported by pinhuer on 2015-04-09 16:47:46

Beep6581 commented 9 years ago
Just a note for me: curve point interpolation does not seem to be symmetric. You won't
get the same interpolant if you invert all point horizontally.

Reported by pinhuer on 2015-05-11 11:17:51