# Which color space for tone-mapping?

This topic is 3569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I notice that GLSL examples apply tone mapping to RGB values directly, which seems to me would be incorrect. However, I'm having trouble figuring out which color space to do the conversion in. Luminance is already in such examples computed as a weighted sum from RGB using matrix values I see used for Y in XYZ color space. Once the luminance is mapped, (I use Y = Y * (Y / (maxY * maxY) + 1.0) / (Y + 1.0); ) I've seen examples where they simply multiply it into the original RGB values. How can that be right? I did try to extract X and Z as well and then convert the XYZ after tonemapping Y back to RGB, but I'm not getting a sensible result...

##### Share on other sites
Hi, I am quite ignorant on this subject, but AFAIK the pbrt raytracer uses XYZ for the color calculations, and it provides tone mapping so I suppose that it is the right (or a reasonably good) way to do it. From the site you can download the source.
Hope this helps

##### Share on other sites
Hi Prune,

I'm experimenting with tomemapping the past few days as well, and as you said, i've also seen a few of demos where they just multiply the HDR RGB value with the adapted luminance. I suppose there is an explanation behind this, but i haven't actually searched for it. Instead, i did what seemed more logical to me. I tried RGB to XYZ, adapt Y and back to RGB as you said. It seems that in XYZ space you can't modify luminance (Y) and get the same color back (either darker or brighter).

What i found out is that you can convert XYZ to Yxy, alter Y and convert back to XYZ (and from there to RGB) and the color will stay (almost?) the same with a different brightness. From this:
Quote:
 It is often convenient to discuss "pure" colour in the absence of brightness. The CIE defines a normalization process to compute "little" x and y chromaticity coordinates:...

Probably by doing all the math on paper (RGB->XYZ->Yxy, alter Y, Yxy->XYZ->RGB) you will find the explanation behind the direct multiplication of RGB values with the adapted luminance.

Hope that helps.

HellRaiZer

EDIT : Forget about Yxy. You can try it and see that it works, but there is actually an explanation behind what most demos do. If you do the math you will find out that the whole thing boils down to :

ldr_RGB = hdr_RGB * (adapted_luminance / hdr_luminance);

I hope i haven't done any mistakes. This will make your shaders a lot simpler :)

##### Share on other sites
It is true that doing it in RGB space is technically wrong.

The problem is, even if you do it "the right way", you'll have trouble to decide which one looks "better".

So what most people do ( including me ) is to go for the simplest/fastest solution, RGB space.

Y.

##### Share on other sites
Wrong, right, there is none.

Tone mapping is taking a high dynamic range picture (one that has data from very small values to very high values) and compress it to a very small range (0..255 integers). That compression will lose some info whatever route you take. The control you have is where you'll lose this info. Some people will prefer to lose brightness info to saturation info. Some prefer to preserve hue, other will want a maximum contrast. Other will prefer to preserve "saliency" at the expense of truth.

There is no right and wrong answer.

##### Share on other sites
Preserving hue, although it avoids the 'washing out' effect, can often lead to very unnatural images.

I usually prefer a weighted mix of a standard RGB space tonemap and a hue preserving tonemap.

##### Share on other sites
Any shader code you care to share, or a general algorithm you use to do this tonemapping?

##### Share on other sites
Quote:
 Original post by LeGregWrong, right, there is none.

I disagree. The way it should be done is one that makes the least visual difference in the human visual system from an equivalent image displayed on an HDR screen. The same way audio and video codecs are studied in blind testing with human subjects needs to be applied here to find an approximately optimal mapping operator.

##### Share on other sites
Quote:
Original post by Prune
Quote:
 Original post by LeGregWrong, right, there is none.

I disagree. The way it should be done is one that makes the least visual difference in the human visual system from an equivalent image displayed on an HDR screen. The same way audio and video codecs are studied in blind testing with human subjects needs to be applied here to find an approximately optimal mapping operator.

Evaluation of Tone Mapping Operators using a High Dynamic Range Display

Suprisingly the the answer might be different when choosing the "best" TMO with/without reference image.

##### Share on other sites
Quote:
 Original post by stephanhSuprisingly the the answer might be different when choosing the "best" TMO with/without reference image.

That's a failure of the specific study mentioned, not the concept that blind testing of perception is the correct approach.

##### Share on other sites
I've been thinking--tone mapping should be on per-cone basis, meaing the light sensitive cones in the retina. The dynamic range compression they themselves do (human senses are all logarithmic) is what one is trying to recreate, and, though the information is fused from the three types of cones in the brain, probably most of the compression happens on the level of the cones themselves. I'm not sure whether the individual components of XYZ correspond to individual cone sensitivity (can someone answer this?), but if so, then the computation should be done in XYZ and separately for each of X, Y, and Z, and of course the parameters of the computation could be different.

##### Share on other sites
If you look at the problem from a practical angle you do want to achieve two things:
- no "wrong" colors under extreme conditions
- being able to tune a neutral state

So what you want to do in a game is tell the artist that he can switch off tone-mapping and the other PostFX and he can tune them that switching them on and off does not make a huge difference. This gives them a great starting ground. What they do now is:
1. switch off PostFX
2. Tune lighting and the environment that it looks good
3. switch on PostFX that are very neutral and tune from there
This gives them a good starting ground and leads to great results. I talked on GDC 2007 about the PostFX pipeline I developed. You can find the slides on the GDC 2007 page of www.coretechniques.info
I did what HellRaiZer found out and what is done since the beginning of HDR :-) ... convert from RGB to Yxy, alter Y and convert back. That works really well, gives you a lot of control and does not break down.

##### Share on other sites

This topic is 3569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628653
• Total Posts
2984050

• 10
• 9
• 9
• 10
• 21