An alternative method of adjusting tonal contrast & dynamic range in Rawtherapee

An alternative method of adjusting tonal contrast & dynamic range in Rawtherapee

One of the components of RawTherapee’s Abstract Profile module in Color > Color Management is the Tone Response Curve (TRC). This has been enhanced in the latest version of dev to provide a comprehensive tool for adjusting the tonal characteristics of an image by acting on the midtones as well as the shadows and highlights. It is applied at the end of the pipeline, just before CIECAM to avoid non-linearities as much as possible and guarantee better quality results.

The TRC is complementary to other RawTherapee modules such as Shadows/Highlights, the curves in Exposure, etc., and can be used in conjunction with them. However, the latest additions mean that it is now possible to carry out all the basic tonal adjustments in one module using just three sliders and a checkbox i.e. a Gamma slider for adjusting the highlights, a Midtones slider for the midtones and a Slope slider for the shadows. The interplay between the Gamma and Slope sliders allows the user to also adjust the global contrast. The Highlight Attenuation checkbox is Ev based and allows the user to soften the highlights for Ev values between 0 and 12 Ev. When used in conjunction with the “Highlight compression” slider in the Exposure tab, it provides a simple and effective solution for controlling mild to moderate clipping, which can easily occur when images have been deliberately exposed to the right.

A basic workflow using the Abstract Profile in the Color tab might look something like this:

  1. Open the image in Rawtherapee and apply a Neutral processing profile. Activate the clipped highlight indication.

  2. In the Exposure tab ensure that “Highlight reconstruction” is activated and set the Method to Color Propagation. If there is significant highlight clipping, you can reduce it with the “Highlight compression” slider but do not try to eliminate it completely at this stage. As indicated in RawPedia, this slider should be used with moderation
    See Exposure - Rawpedia

  3. In the Color tab, open the Color Management module, activate Abstract Profile and select the Custom option in the drop-down menu.

  4. You can now adjust the tonal contrast as follows:
    • If there is any residual clipping activate the “Highlight attenuation” checkbox.
    • Lift the shadows by using the Slope slider. Values up to 300 allow a significant transformation of the image in the shadows.
    • Adjust the highlights with the Gamma slider. Note that increasing the value will not introduce any further clipping, especially if the “Highlight attenuation” checkbox is activated. This is particularly useful to help avoid the problem of flat or dull images mentioned in the above RawPedia reference.
    • Adjust the midtones with the Midtones slider. This should avoid having to use the Exposure slider in the Exposure tab, which gives inferior results. The module includes a B&W conversion checkbox, which can be helpful sometimes when adjusting the mid-tones.

*Note that the Slope slider is only active for values of Gamma >1. Because of the algorithm used to generate the tone response curve, it will show erratic behavior when set to values below 1 and greater than 0.It behaves as expected when set to zero

Further refinements can be carried out if necessary with the usual RawTherapee tools such as the Tone Equalizer and the Lab Adjustments modules.

Future enhancements, which are currently being developed, will include a simple wavelet-based contrast equalizer with preset contrast profiles.

A more advanced version of the TRC can also be found in the Selective Editing tab Selective editing - Cam16 with HDR pre-processing which now has a global spot method to simplify global edits using the selective editing tools.

Jacques

6 Likes

The Pull Request “Abstract Profile – Contrast enhancement”

As noted in the thread “An alternative method of adjusting tonal contrast & dynamic range in Rawtherapee” - Future enhancements, which are currently being developed, will include a simple wavelet-based contrast equalizer with preset contrast profiles.

The development of the wavelet-based contrast equalizer has been completed and is available for testing (binaries for Windows and an Appimage are now available). The following information is a summary of the basic principles. Further information is available in the Pull Request on the GitHub.
Pull Request
Executable - binaries ‘apseimprov’

The Abstract Profile module allows you to obtain a satisfactory result in most cases, with very little manipulation. However the image may lack the contrast required to achieve a more pleasing, more dynamic result. Increasing the overall contrast will not allow you to separate the main subject, or work on the detail in images of buildings, animals, flowers etc. In these cases, it is more appropriate to use the existing contrast broken down into levels of detail and modify it to suit your tastes and the image.

To achieve this, I have used the wavelets tools to develop “a simple wavelet-based contrast equalizer with preset contrast profiles”.

Wavelets are powerful but complex. They have been implemented in a number of tools already in RawTherapee but they are often complex and in some cases lack functionality e.g. Local Contrast in the Selective Editing tab, Contrast in the Advanced tab and Contrast by Detail Levels in the Detail tab can all be used to adjust contrast on a per-level basis.

The concept of Local contrast”: faced with the problems inherent in contrast by level, I decided a few years ago (around 2013) to take a different approach to wavelet contrast. For each level and direction, I evaluate the shape of the signal (average, standard deviation, maximum for positive and negative values). The whole thing is modelled in such a way that the user is faced with a single curve for modifying the contrast, whatever the level. This curve uses the characteristics of the signal to position the mean value at the centre of the graph, and position the maximum at the far right of the graph. It weakens the action for large values close to the maximum. The system’s behaviour avoids the majority of artefact problems, and acts in a fairly similar way across the different levels of detail. I’ve called this approach ‘Local contrast’, but this doesn’t really convey what it does. This tool is present in Rawtherapee in the Wavelet Levels > Final Touchup module, in several other modules such as Wavelet Levels > “Edge sharpness” and in Selective Editing > Local Contrast & Wavelets. It can also be found in ART.

Curiously, until now this tool has not been available separately in the tools available in full-image mode.

Variable contrast

However, despite this improvement, the system cannot, at the same time, and with the same quality as seen from the user’s point of view, process the levels containing small details and those containing large details in the same way. This is why I propose to combine the action of the two systems (“Contrast by levels” and Local Contrast) into a single system.

In this new system, which I have called Contrast Enhancement, per-level contrast is contained in a series of contrast-profile presets, which provide the information needed to adjust the amount of local contrast in each of the levels.

Each preset contains a selection of decomposition levels : slider « Contrast profile »

These presets are classified :

  • from the least aggressive, corresponding essentially to the lower settings of the Contrast by Detail Levels tool, with the number of detail levels limited to 6.

  • to the most aggressive, going so far as to use the maximum possibilities of the system (memory, size of the Preview).

In each of these levels : the low-contrast-value samples and the high-contrast-value samples (which are often synonymous with artifacts) are attenuated. The nature and intensity of this attenuation depends on the preset and whether or not “Highlight attenuation” has been activated.

Each preset also contains information used to weight the overall level data to either attenuate the data for the first level (to reduce noise) or to progressively attenuate it for the higher levels.

The resulting data from each decomposition level is then sent to the curve, which should be preferably “bell shaped” to concentrate the action on the useful levels and attenuate the action at the extremities.

A Refinement expander, which can be used to modify: a) the distribution of the action between the low, medium and high values of the “Variable contrast” curve, in particular by widening or narrowing the effects of the width of the curve; b) adjust the residual image after decomposition to compensate for excessive effects linked to the action of the curve and the presets.

Jacques

5 Likes

Just playing/abusing/experimenting with your new machine…

2 Likes

I’ve done some tests with the new functionality. Just a few comments:

You can now achieve decent exposure/contrast using only Abstract profile tools. :+1:

For me the most obvious difference using Abstract Profile/Contrast Enhancement compared to Tone Curve is that with the former you can get results that are visually equally contrasty as the latter but with more shadow detail. This is of course a result of the local contrast effect of wavelet tools. This often useful but also mangles the image tonal range somewhat.

For users I think it’s important to explain in Rawpedia etc that the sliders might stop having effect mid range. Gamma goes to 20 but might stop making visual difference at 9 depending on the photo. It’s unusual to have sliders that stop having effect mid range and this should be pointed out early in any docs to avoid confusion.

Are the sliders independent or do the effect and “scope” vary based on the other two sliders? It felt as if changing Slope changed the possibilities with Gamma for instance. When testing further I’m no longer sure if that’s the case. Would be great to have clarification.

The current ui solution with an expanding Abstract profile section using the power button icon is confusing. You can’t tell if the module is expanded or not using the default theme. The ui pattern is used in the Selective Editing Colour appearance module where it works ok even if it’s a bit confusing there as well. Something about the layout, position in stack etc. in the Colour management module makes it more confusing there.

I think Abstract profile should be it’s own module. For a user, in terms of workflow, Abstract profile is not related to input or output profile. Technically they might be related but not in terms of workflow. Imho technical or code ancestry are irrelevant for users and should never be a reason for organizing ui.

Edit: Another thing. It seems Contrast enhancement with variable contrast set to linear has no effect regardless of Contrast profile? It also lacks obvious “off” setting.

2 Likes

Although I like Contrast By Detail Levels and use it a lot, I could never get along with the Wavelets Tab User Interface in RT. Not saying that it isn’t good but I prefer the more simple approach in the GIMP - where one can do anything GIMP-wise to any Detail Level and combine them just like normal layers prior to merging.

1 Like

@paulmatthijsse @nosle @xpatUSA

Thank you for testing this module, and excuse my bad english.

The notion of “Abstract profile” (AP) that I presented about 3 to 4 years ago sparked heated debates at the time (to put it mildly). Two aspects highlighted :

  • The first related to the notion of « profile », incorporated inside the code and not at the beginning (input) or at the end (output), without forgetting the “working profile” (which in fact is not an ICC profile) . Because in “abstract profile”, gamma, slope and all the primary parts use an ICC profile (which the user does not see) to modify the data. It is by using these features that @paulmatth was able to create this original image (it’s like a channel mixer on primaries). This is why, at the time after long and heated debates, AP was positioned in the same module as the ICC and DCP profiles. I would come back.

  • What a difference with a classic tone-curve. Here too the debate was long (several months). As you point out, with AP, we have better control over low light and, above all, we apply completely linear processing. This allows for better control of noise and tones, which is not the case (in general) for curves and also for Log conversions.

As a reminder, the gamma/slope system works by connecting a straight line of variable slope (“slope”), with a parabolic curve of variable power (“gamma”). There is no discontinuity.

To function the gamma/slope system necessarily requires a slope greater than 1 and a gamma greater than 1. The greater the slope must be (to act on shadows), the higher the gamma must be. The continuous connection relationship is obviously not linear. This will depend on the image, the depth of the shadows and the value of the highlights. We should (I hope) be able to improve the documentation on this subject a little.

Indeed I increased the gamma value a little, mainly because I propose to start from a “Neutral” image therefore without “Auto-matched tone curve”. In the same way since the creation of AP and its equivalent in Selective Editings, I increased the slope value (now to 300).

At first assessment the possible increase in gamma has little effect. As I said, it depends on the images, but the gamma at the same slope (let’s say 150) will make it possible to differentiate the action on the mid tones (L – “Lab” - around 50 to 70). We will thus have a more concentrated curve towards the lights.

Of course we can prefer Contrast By Detail Levels (CBDL) which is a poorer version of wavelet (Harr’s method - which can generate artifacts) and is simpler to learn than « Wavelets levels ». As we may prefer the solutions implemented elsewhere (Gimp, DT…). Richness lies in diversity.

What I wanted to achieve here is a tool (Local contrast) that I imagined 10 years ago, which was acclaimed in ART (where since then, CBDL has been deleted) . I wanted to complete it in the current form (with the Contrast profile). If I hadn’t written in the presentation that it was 100% based on wavelets, would you have seen it (with the exception of the Refinement expander).

All that remains is the GUI part. Where to put this module (debate in 2021)? And with what commands to initialize it, etc.

It may seem obvious from the user side that a module’s functionality and its technical complexity and graphical interface should not have to be taken into account.

Fortunately (or unfortunately) the implementation of RT is what it is. We can thank Gabor Horwatz for designing RT in 2006. However, the constraints are strong, also linked to history and habits. For example : 1) why did we put the “Exposure” tab at the forefront, when here it is almost of no use ; 2) the preview only works well in the majority of cases with a 100% zoom ; etc.

And in general what is in what? The ideal would have been (and would be) to have small GUI modules that we could put wherever we wanted, notably with “Favorites” in “Preferences”. These small modules (if we have solved the problem of transforming the large modules) certainly have advantages in terms of use, but they complicate the development of the GUI code and processes (events).

But this is not the case. Four years ago for ease, for logic, I incorporated AP into the GUI of the “profile” part. There is also a logic to inserting it in terms of visibility with White-balance and the corrections that can be made to the profiles (DCP, etc.), and the part « primaries and illuminant » of AP - all in the tab Color .

Taking AP out of this GUI module and making it standalone is certainly possible. This requires a lot of work, because the entire RT code is dependent on it (pp3, batchs, etc. , and ensure compatibility with older versions of RT). I think this may be subject to future development, but in this case we would have to re-examine the entire RT process and GUI, which is no easy feat.

The point you raise is that an “off” settings is missing. I don’t have a clear opinion on the subject, the majority of curves only have the “linear” / “equalizer” toggle, but it is possible to add a control for example at the level of the “Contrast Enhancement” expander.

I remain open to any proposal that is feasible within a time frame and with a reasonable volume of work.

And thank you again for these reviews.

Jacques

1 Like

Yes, I’ve noticed that also. It seems that the more you lift the shadows, the more you need to increase the gamma to maintain the contrast* but I’m not sure if that is a hard and fast rule. Maybe Jacques @jdc can clarify that ?

It is convenient having it in Color Management if you want to toggle through different DCP profiles without having to switch modules modules each time. I’ve found that some DCP profiles are better than the camera standard or auto-matched camera profiles when it comes to preserving highlights (even with the DCP tone curve switched off), especially for small sensor cameras.
Having said that, you are right that it would be more logical to have it as a separate module.

EDIT: * on some images I can still see a noticeable difference with gamma slider values of 15 when the slope slider is midway.

@Wayne_Sutton
That’s what I’m trying to explain here. The gamma/slope system where a power curve “n” (gamma) is connected to a line of slope “p” (slope), can only be continuous under certain conditions.
The greater the slope, the more latitude you will have to play with the gamma. For example if you have a relatively low slope (less than 20), the action of the gamma variation will be very moderate (as a reminder the basic sRGB gamma applied in RT gamma=2.4 slope=12.92). But if the image (or your choice) leads you to use a slope of 200 or more then the entire gamma range will be useful, especially for luminances around 50 to 80 (scale to 100).

sorry @jdc , I didn’t see your reply before I posted the message.

1 Like

I find the sliders work well and that the way they depend on each other becomes second nature. It’s not a problem per se that the sliders stop having effect. To help new users though I think it should be simply stated very early in the docs that

  1. Sliders may stop affecting the image half way.
  2. The sliders are affected by each other.

More detail isn’t necessary and the behavior is quickly self evident.

The position of the module in colour management works and i fully understand if it’s left there for practical/time constraints. I give opinions on these ui things because I don’t see much discussion about it and for users having a smooth and clear workflow is amongst the top issues with software such as RT.

Have you tested the new interface this thread is about?

I guess I was confused about two things.

  1. Contrast profile: is a 0 setting an off setting?
  2. A linear “curve” in the equalizer doesn’t mean no effect if said linear “curve” is at O 0.7? So I thought linear just meant that the effect is the same across detail levels. It wasn’t clear to me that a contrast profile of 4 and linear variable contrast was an off setting.

Some ui thoughts based on the new info.

  1. Perhaps the Equalizer should come first in the module. Before the Contrast profile. This will help signal the off nature of “linear”. I expect settings that give immediate effects to come first in tools. Ways of tweaking said effect comes after. (reading top to bottom)
  2. Change the Linear label to Off in eq. (or other non ambigous label)
  3. Perhaps Contrast Enhancement doesn’t need it’s own expander? Abstract profile is quite short compared to many other modules. This of course depends on how often one expects contrast enhancement to be used compared to say Primaries etc.
1 Like

@nosle @Wayne_Sutton and others…

What I suggest to you, because we cannot do everything and its opposite at the GUI level. Each time the choices are difficult.

What drives the user’s personal logic?
What GUI logic (and underlying algorithm) should or should not guide the user?
There is (fortunately) no right answer.
I completely understand your arguments, which will probably (and this is in no way a criticism) differ from another person. I will offer you a compromise that does not require many modifications (a few hours…)

  • graduate the “contrast profile” axis from 1 to 6 instead of 0 to 5, to avoid the connection 0 = no action.
  • put an activation button on the expander, but leave the expander in place. With this, the contrast part is only activated if necessary, and the GUI interface is compact.

I can also easily move the curve and the slider “Contrast profile”.
For me the logic of the designer

  • first - choose the aggressiveness of the system (Contrast profile)
  • second - adjust the desired effects according to the preset above with the curve
  • third - incidentally refine the result with “refinement”

But of course, other opinions are welcome, and I’m open to any reasonable suggestions.

Thank you again

Jacques

No, I’m sticking with 5.8 for now, should have said. RT is no longer my go-to editor.

Hello everyone

I made the changes I announced yesterday

  • Expander “Contrast Enhancement” - enable or not
  • Change range “Contrast profile” from 0 - 5 to 1 - 6 (of course I change the default value, from 2 to 3).

In addition, to facilitate use (now that there is the possibility of activating or not the “Contrast Enhancement” set), I have initialized the bell curve with a default value which should be suitable in the majority of cases.

Of course I can change all that, if need, including the order between the curve and the preset selector (contrast profile).

Executables
apseimprov

Jacques

3 Likes

Hello

I have just added to the methods for processing difficult images (highlight attenuation, etc. in Source Data Adjustments), another method directly from Darktable “Sigmoid Tone mapper”.

Now you have:

  • None
  • Ev based
  • Gamma based
  • Slope based
  • RGB channels slope
  • Sigmoid based

The code is essentially identical to that of Darktable and that of Sigmoid Tone Mapper in ART (with CTL). Thanks to the DT developers and Alberto @agriggio

I brought some skills, notably taking into account DR (dynamic range) and Yb scene. This led to changing the default settings, but does not call into question the operation.

image

Executables apseimprov
https://github.com/Beep6581/RawTherapee/releases/tag/pre-dev-github-actions

I updated the comparison of the various methods for evaluation of the dynamic-range capabilities of tools in Selective Editing, now with Sigmoid.
Evaluation Dynamic Range

  • note, that the “Slope based” (about 23.5Ev) and “Sigmoid based” (about 22Ev) methods need to be “preprocessed” with the TRC to obtain good results
  • also note that “Sigmoid based” obtains good results with the automatic consideration of “Yb scene”, “White point” and “Black point”
  • also note, that there must be other possible settings (White distribution, Black distribution, TRC gamma/slope, etc.)

Jacques

4 Likes

What is “Yb scene”, please?