I use RawTherapee 5.9 for DNG file processing and DCamProf for creation DCP profiles that are used in RawTherapee Color Management.
Usually I created the tone curve in RawTherapee and copy it to the DCP profile and it was okay.
However, recently I decided to divide the tone curve that I used to two separate curves, one of them put to the profile and another one - left in RawTherapee.
So task that I have is to divide tone curve to two separate tone curves that give me the initial curve when I sum them (probably you correct me here, but as I understand the algorithm the DCP tone curve was applied on the conversion step and Exporsure tone curve applied to the result of conversion).
On the first step I decided to simplify my task, as RawTherapee has two curves in Exposure.
For the testing purpose I took Standard Film Curve - ISO Low from RawTherapee Bundled Profiles. So the parameters of curve are:
Spline
0 0
0.11 0.09
0.32 0.43
0.66 0.87
1 1
The curve the curve I want to subtract from it has next parameters:
Spline
0 0
0.0702614 0.0604575
0.276611 0.330544
0.599693 0.67976
1 1
I decided that it might be good to use Python or something like that to calculate second curve. So, please see the code below:
# import some libs
import numpy as np
import matplotlib.pyplot as plt
# the first spline points
x1 = np.array([0,0.11,0.32,0.66,1])
y1 = np.array([0,0.09,0.43,0.87,1])
# the second spline points
x2 = np.array([0,0.0702614,0.276611,0.59969,1])
y2 = np.array([0,0.0604575,0.330544,0.67976,1])
Now I need some info about how the spline in RawTherepee (and DCamProf) was build.
(Unfortunately I am not so good in C to get this information from the sources)
As I currently don’t have this information, I supposed that it’s probably interpolation with degree = 3 (cubic spline):
# The degree of the polynomial for interpolation (cubic spline)
degree = 3
# let's get some coefficients
coefficients1 = np.polyfit(x1, y1, degree)
coefficients2 = np.polyfit(x2, y2, degree)
# and find the difference
coefficients_difference = coefficients1 - coefficients2
# Probably now we need to evaluate the results
# Define the desired range for x and y
x_min = 0
x_max = 1
y_min = 0
y_max = 1
# Create x values from 0 to 1
x_values = np.linspace(x_min, x_max, 100)
# print(x_values)
#result difference spline
y_values_difference = np.polyval(coefficients_difference, x_values)
# Calculate the corresponding y-values for each spline
y_values_spline1 = np.polyval(coefficients1, x_values)
y_values_spline2 = np.polyval(coefficients2, x_values)
#result difference spline
y_values_difference = np.polyval(coefficients_difference, x_values)
# and now we need to add the current x-value to each element of y_values_difference
y_values_difference_with_x = y_values_difference + x_values
I do this because I need to get the points for the result spline, so:
# Calculate the corresponding y-values for the difference spline at x1 points (same points as the first spline)
y_values_difference_with_x1 = np.polyval(coefficients_difference, x1) + x1
So, here the results that I’ve got:
The initial Standard Film Curve - ISO Low spline is red, the spline that was subtracted is blue, the result spline is orange.
And points that I’ve got:
# prepare for printing
# np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})
np.set_printoptions(formatter={'float':"{0:0.5f}".format})
print("", x1, "\n", y_values_difference_with_x1)
[0.00000 0.11000 0.32000 0.66000 1.00000]
[-0.00253 0.10071 0.35891 0.79482 0.99909]
To compare, the initial Standard Film Curve - ISO Low spline in RawTherapee:
So I have several questions:
-
Is it possible to get any info about the math that used to build the splines in RawTherapee?
(It is obvious that even initial spline (red) doesn’t match with spline in RawTherapee. Furhtermore red spline go above 1.0). So what algorithm was used in RawTherapee? -
Can anybody recommend something to resolve my task in easy way?
-
If anybody has any information about DCamProf, if it use the same approach to build the splines as a RawTherapee?
-
RawTherapee has several algorithms that might be used for Tone Curve (Standard, Flexible, Parametric, Control Cage) all of them have features, sometimes it is better to use one, sometimes another is it possible to divide for example the Standard curve between Control Cage and Standard, or between Parametric and Standard?
(as RawTherapee has Film-like, Perceptual, Saturation and Value Blending, etc. algorithms, it might be used for interesting color effects, so it will be possible to blend that algorithm based on two tone curves, change colors but get exactly the same resulting tone curve)
It was a little bit long, sorry, but I wanted to describe the problem.
Thank you for any help and any information!
Best Regards,
Dmitry