filmic rgb: basic questions

Hi, I’m new to darktable and playing around with the ‘filmic rgb’ module. I like its output very much so far, however, I’d like to understand its mechanisms a bit better. Sorry, if the following questions are somewhat obvious or too basic:

  1. How is the middle-gray luminance (0 EV) actually calculated? Referring to the input luminance of the module, is it simply: min + 0.1845*(max-min) ?
  2. How are the default values of white and black relative exposures actually calculated?
  3. How are the relative exposures with “auto tune levels” actually calculated and why do they differ from the default values?

Many thanks!

1 Like

They are not calculated. They are simply the default values. Presumably they were chosen because they work well across a range of different images.

As I understand it, the algorithm tries to find something that looks like pure white or black, and sets the values accordingly. This is also why it can fail if there’s no almost-black in the image.

When I reset the module, I get different ‘default’ values for different images, hence I assume that they are somehow calculated. I’d like to understand, where these values do come from.

Yes, that’s obviously how it works. However, I’d like to understand how it works in detail and why it differs from the values when the module is resetted.

I always get 4.65 for white and -7.65 for black. Doesn’t matter what I do.

I suspect you’ll have to dive into the source code to find out.

Haven’t watched it myself, but this video might explain more:

It does read something in the meta data of the file I forget what. Otherwise it defaults to around 4 and -8… It really is not important …The main thing for it to work is nailing exposure. Then you can start with the auto pickers and after some experience set more or less compression for highlights and shadows… Basically you are setting exposure to determine middle gray in your eyes or to expose your main subject as you like then you use filmic to map the DNR of the highlights and the shadows around that central point… other modules will use that central point as a frame of reference as well…

IIRC it uses the exif “exposure compensation” value to adjust the black and white exposures (works in conjunction with similar functionality in the exposure module)

2 Likes

I was going to say that but didn’t want to just go by memory…thanks for filling in the blanks for me…

The filmic RGB module is quite often difficult for me. That’s why I only use the Sigmoid module lately. I usually get a good result faster than filmic rgb

2 Likes

One question that hasn’t been answered so far:

It’s not calculated at all; it is, by definition, at 0.1845 luminosity in the module input. It’s up to you to ensure that the areas in your image you want at that tonal value, are there before filmic (exposure, tone equaliser, …). That value is then considered by filmic as 0EV, i.e. it’s the reference point for the other EV values.

To be complete, you can tell filmic to use a different value as middle gray, which will then be mapped to 0.5 in the output, but that’s not recommended (or needed). It may also be a leftover from the first iteration of the module, so it has to stay for backward compatibility.
So, the 0EV is a user-defined point, which is always mapped to a fixed output value, and by default, the input value of 0.1845 is used.

1 Like

I don’t think that this is correct. In scene referred workflow, input values are not limited to [0, 1], but are allowed to exceed 1. So my questions was, which input value corresponds to 0 EV and how this mapping is calculated.

Middle-gray (0 EV) is not mapped to 0.5, but to 18% of the display, just have a look at the graphic display in the module.

I appreciate the willingness to help of you all, however, I don’t think that any of my inital questions has been answered definitively. This confirms for me that this module is not well understood in general and, unfortunately, I didn’t find answers to these seamingly simple questions in the official docu, nor in the youtube video linked above.

Is the author of the module active in this forum?

Since you don’t know the answers already, I’m not sure how you can know this. It seems that you just disagree with the answers you’ve been given.

  1. Middle-grey is assumed to be 18.45% at the input of the module
  2. Default values are set based on the exif exposure compensation along with some hard-coded values that have been tuned to give a reasonable starting point for most images
  3. Relative exposures are calculated by sampling the image and trying to detect the brightest and darkest pixels in the sample area

No, he left and now runs his own fork of darktable and hosts his own discussion forums.

2 Likes

Sorry, no offense. I‘m interested in the maths behind this module. However, your answers are still helpful. Thank you!

If you can understand the maths, then you can probably get some useful information out of the code – it’s pretty well commented: darktable/src/iop/filmicrgb.c at master · darktable-org/darktable · GitHub. But you ask about the maths, and I’m not sure any of the questions you initially asked really have mathematical answers. The numbers are “what looks good” or “some statistical maximum/minimum pixel value from a selection” or “the definition of mid-grey”.

2 Likes

I believe the original comment stated that the OP liked the output… then 3 questions were asked. I think they were answered. But as to the output there is gamma, the gamut mapping, HLR and in previous versions the color preservation modes impacting the look of that “output” so there is no simple answer IMO but to dive into the code and try to follow the flow for each of those corrections. Also given the combinations of those factors that are at play the output will really depend on those selections which we all know can produce quite different results…

1 Like

In that case, the only solution I see is reading the relevant code (as has already been suggested).

This article from the original author of the filmic module might also show some more details (fairly long, and treating the original filmic RGB module, there have been changes since that version) He also has several videos on Youtube about filmic.

That is correct, but mid-grey is still defined as 18% reflectance. 1 means 100% diffuse reflected light (e.g., snow). Values above 1 are light sources and specular (mirror-like) reflections.
Also, that statement of yours does not contradict what @rvietor told you. He was not wrong.

You can, of course, use exposure and tone equalizer to move any input pixel to the 18% point.

White and black relative exposure are set according to what portion of the dynamic range, theoretically infinite below and above, you want to represent in the output.

2 Likes

But since we generally do not know the luminosity of the original light source (if applicable), we cannot calculate reflectance based on sensor data, so I am not sure how this is relevant.

The “middle gray” in the filmic source code could be just any positive number. It is currently hardcoded to be 18.45, but… I have not seen an explanation for this that makes sense. Neither for the option of changing it.

It is best to think of modules before filmic rgb or sigmoid operating on a log(2) scale: exposure just adds a constant, but you have to pin this down somewhere, hence log(0.1845). It really could be anything as long as it is determinate.

FWIW, I think that filmic rgb is the most confusing module of darktable. It does a lot of things, and it is hard to say what it does without delving into the source code. Moreover, there are currently 5 “versions” of the module, each with subtle changes and a ton of options. Lacking clear understanding, users resort to experiment (“v5 max rgb norm looks better than v6 luminance norm”) but there are so many permutations.

I think that at this point it would be better to give up the pretense that filmic rgb is somehow based on “color science”: it has been an iterative design improving on various heuristics, with each iteration fixing some issue and introducing new ones. Yes, moving to the scene-referred workflow was a great idea, and filmic rgb was essential for that. But eventually, sigmoid is much cleaner IMO, and a lot of stuff that it is missing compard to filmic can be done much more cleanly in other modules.

3 Likes

Sorry, but no, there’s no need to pin anything for the exposure module: Adding 1 EV means multiplying all values by 2. This is absolutely independant of any fixed point (or the fixed point is 0.0, if you want). The 0EV just means “multiply by one”. The same goes for any other linear operation in linear space: you don’t need an anchor point.

Otoh, filmic (and sigmoid) have an inflection point in their tone mapping curves. In filmic, that “point” can actually be a linear region when you use the “latitude”. That’s also the point where you measure the contrast (using the tangent to the curve in that point) . So it makes sense to set that point at “middle gray”, as that’s where you mostly want to control the global contrast.

1 Like

But your “various heuristics” is too vague to mean anything. So then what do you suggest?

Isn’t this how engineering works? I don’t understand the point you’re trying to make.

I can’t abide by the language here, as that would leave filmic as the “dirty” solution, which doesn’t really mean anything.

Sigmod has less sliders so it might be perceived as easier to operate, it might be easier for lay people.

Instead of being “dirty” or “complicated” filmic offers very fine grained control.

It all depends on how one wants to view it, and since you said “IMO” then that’s fair enough.

Certainly you can compensate for the lack of control in sigmoid elsewhere, but the ends might not be the same, as the controls in filimic effect a lot of color and contrast in ways that might take multiple instances of other modules to replicate.

Again, I can’t abide by the clean/dirty language here. There are options, and thats one of the great things about darktable.

2 Likes

A single slider (or even just a single button) is cleaner than an aeroplane-cockpit of a module but is it really better? I prefer having control over all the parameters, even if I often don’t need it.

1 Like