Finding a norm to preserve ratios across non-linear operations

Thanks.

For now, ProPhoto RGB but that will be extended to whatever RGB for dt 2.8.

Local workarounds that just work backfire sooner or later.

again, sorry but I don’t understand why argmin and not min

Just call it max if you prefer.

anyway, more general comment: thanks for starting this discussion. I find it quite interesting. Unfortunately I don’t have the necessary physics background to contribute to your analysis, but I’m certainly interested in the outcomes.
I can only contribute with my empirical observations, that match more or less what you wrote in your initial post. Using max as a norm gives not so pleasing results (in particular, it tends to compress blue skies too much). Euclidan norm works better in my experiments, and so does luminance. But I don’t have much physical justifications I’m afraid…

but they are two different functions – hence my question :slight_smile:

Ah. Found that https://jo.dreggn.org/home/2015_spectrum.pdf by @hanatos (it’s a small World), so maybe we can compute an approximation of I(\lambda) after all (from XYZ) and then numerically integrate it so the energy computation is direct (but expensive).

Indeed, it’s a simple max in this case.

… if you’re on the search for fast spectral upsampling, may i suggest you also look into this one: https://jo.dreggn.org/home/2019_sigmoid.pdf ? caveat may be that colours in images will encode emission and not reflectances, so you’d need to scale before and after upsampling.

5 Likes

thanks !

and yes, if i may add: i find this topic super interesting. the distortion in chroma that a tonecurve brings has always annoyed me and i think we can do better by doing things in spectral. the upsampling is really only using a couple fma + one reciprocal sqrt instruction and can be executed in SIMD on many wavelengths quite efficiently. i’ll be excited to hear about any more ideas or results in this direction.

3 Likes

Can I take a step back? For the norm, what is wrong with using luminosity or similar?

In other words, why not simply apply the tone curve to L of Lab or Luv, or Y of XYZ or xyY?

@snibgo There is a desire to move away from the Lab model. See: Darktable, filmic and saturation - #73 by aurelienpierre and related threads.

Would it be reasonable to estimate the spectral response of each sensor by taking a Gaussian around, let’s say, 454 nm, 540 nm and 610 nm? See e.g. https://www.dxomark.com/About/In-depth-measurements/Measurements/Color-sensitivity for a sketch.
That could give you a starting point to try out if the energy-oriented method actually works.

@snibgo in my experience, Y works reasonably well (e.g. it’s what is used in the dynamic range compression tool of RT), whereas L of Lab produces quite unnatural results. I’m sorry I can’t provide a more meaningful/quantitative answer, but my knowledge in these topics is too limited for that.

Yes, I have long been wrestling with Lab. When I change L values, I need to adjust C ones to compensate in order to get more natural results and vice versa. There are other Lab-like spaces but I haven’t tested those because they aren’t readily available.

Did you ever try it ? In darktable, you can use the tone curve in XYZ or Lab or RGB. What happens then ? XYZ shifts colors toward yellow/green, Lab creates blueish-greyish shifts when you raise the shadows luminance. So, they don’t work. Besides, Lab is a color adaptation model more than a working color model (to push pixels).

Luminosity (Y or L) is perceptually defined. This has nothing to do with actual light/photons behavior. Sticking to physically defined spaces and reproducing in software what would happen to photons IRL has been found to often give the best and most intuitive results, so the retouching process is faster and more reliable.

It’s a blind guess really. How do you know the mean and std of your gaussian ? If it’s to find yet another nasty workaround, that project becomes pointless. Let’s be rigourous.

Lab is known to not shift hues linearly. After all, it was one of the first attempts to mimick human perception (1976). Also, I vaguely recall some weird kinks happening around blue in Lab. TL; DR Lab belongs to museums.

Provided you use xyY (not XYZ) and still, I find it brightens reds too much.

These Lab-like spaces (JzAzBz, IPT, etc.) are good mostly to perform gamut mapping when you want to reduce the visual difference (Delta E) between source and destination. They are still not intended to do general purpose color grading (except maybe rotating selective hues).

I appreciate your desire for rigour! Though some spectral response curves have been measured (as per my link for an example) and could be used to determine approximate gaussians as a first estimate to test if you can even get anywhere close to your desired outcome. Even an imperfect model is usually already very useful, as countless examples in science demonstrate, no?

The problem is not whether or not to use an imperfect model, all models are imperfect. The problem is to determinate how much imperfect the model is. For example, if we are able to find an upper bound for the pixel energy, in addition to the lower bound I have found, and say we take the average of both as our energy estimation, we will know that the max error of this estimation is half the range (max - min). Then, we could try to write a solver to refine that first estimation and get a more accurate one.

If we use the spectral distribution of some sensor for some other sensor, we have no idea what this error is. So it’s not even a model, it’s a blind guess.

Getting a result is not enough to be science, or even engineering for that matter, you need to know how much you can trust that result.

Also, we don’t really need the full spectrum here, but only its energy, wich is an overall/global property of the spectrum. You can compute it directly by integrating the reconstructed spectrum of a pixel (plan B), but, coming from thermic engineering, I feel there should be a more simple way to deduce it from the properties of said spectrum.

As far as I understand, the method described in the SMPTE2017 talk you linked in the first post works quite differently from DT’s tone curve in XYZ or Lab colorspace.

The idea is actually quite simple:

  • define a norm of the RGB vector, and compute it for the input RGB values (N_i)
  • apply the tone mapping to N_i, obtaining N_o = TM(N_i)
  • compute the output/input norm ratio: R = N_o / N_i
  • scale the input RGB values by this ratio: RGB_o = RGB_i * R

The last step is basically an exposure compensation. For it to work properly, the RGB_i values have to be linearly encoded, and the norm should preserve this linearity (Lab L is not a good “norm” for example).

I am pretty sure that this is not equivalent to a an adjustment of the Y channel alone in XYZ colorspace, nor to a tone curve applied independently to the three XYZ channels. The latter seems to be what DT’s tone curve module does when “XYZ, linked channels” is selected (see here).

hence I am not really surprised that the tone curve introduces color shifts also when used in XYZ colorspace…

I absolutely agree on this, and I have also started thinking about spectral up-sampling as the good solution. However, I didn’t have so far the time to actually code anything…

Yes, that’s what I meant when I wrote “this is what the DR compression tool of RT does”.

1 Like

Yes, the tone curve does not work on Y only, but I have experimented on filmic in xyY space, and it’s still not good enough. I really believe we should tone map the energy and rescale the spectrum accordingly.