Jump to content
  • Advertisement
Sign in to follow this  
wolf

Color Contrast

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, a good post-processing pipeline also covers a way to increase contrast. The following source code snippet shows how this is done quite often: float3 Cont = (color - 0.5f) * Contrast + 0.5f; Because the value range is restricted to the area of 0..1 at this stage of the pipeline, what this code snippet does is make dark colors brighter and bright colors darker. In other words it decreases the contrast. Moving it to any other place in the pipeline where the value range is bigger wouldn't help either, because it can not really increase the values of colors. I find this slightly unsatisfying. A W3C working draft has the following interesting stuff to say about color contrast measurement.
Quote:
The W3C Working Draft from 26. April 2000 [W3CContrast]   Two colors provide good color visibility if the brightness difference and the color difference between the two colors are greater than a set range. Color brightness is determined by the following formula:   ((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000   Note: This algorithm is taken from a formula for converting RGB values to YIQ values. This brightness value gives a perceived brightness for a color. Color difference is determined by the following formula:   (maximum (Red value 1, Red value 2) - minimum (Red value 1, Red value 2)) + (maximum (Green value 1, Green value 2) - minimum (Green value 1, Green value 2)) + (maximum (Blue value 1, Blue value 2) - minimum (Blue value 1, Blue value 2)) The rage for color brightness difference is 125. The range for color difference is 500.
Any thoughts, comments? - Wolf

Share this post


Link to post
Share on other sites
Advertisement
Without venturing into the domain of HDR, this is all we can do.

While that formula you quoted gives a good way to calculate brightness, it's not very useful for making contrast transformations. If a colour is to be brighter, it needs to be scaled up uniformly, else its chroma value will change. The brightness formula doesn't factor into it.

You may want to take a look at gamma correction. When used carefully, it can give a more convincing dynamic range to a scene whilst sidestepping messy saturation issues.

Regards
Admiral

Share this post


Link to post
Share on other sites
Quote:
Original post by wolf
float3 Cont = (color - 0.5f) * Contrast + 0.5f;

Because the value range is restricted to the area of 0..1 at this stage of the pipeline, what this code snippet does is make dark colors brighter and bright colors darker. In other words it decreases the contrast. Moving it to any other place in the pipeline where the value range is bigger wouldn't help either, because it can not really increase the values of colors.
I find this slightly unsatisfying.

Sounds like the value of Contrast is less than 1. Try using values bigger than 1.
Please note that doing so, you are loosing detail because color values can be mapped outside [0,1].

A better alternative is to borrow from the known "S"-curve technique which is commonly used in Photoshop's "Curves".

Let's define:
f(t) = t - a(t-1)t(t-1/2),
where a is used to adjust the contrast. The higher the a, the stronger the adjustment.
Of course the value of 0 means no adjustment at all.
Suggested values for a are usally in the [0,2] range.

For small enough values of a, f maps [0,1] to [0,1] so the loss of detail is minimal.

Although f(t) is only a cubic polynomial, its computation can be expensive. If possible, consider using a 1D texture to post-process the color output of your pipeline.

[Edited by - ury on November 27, 2006 5:13:28 PM]

Share this post


Link to post
Share on other sites
Hey ury,
this sounds great. Can you provide me with any reference for this, so that I can read up this stuff?

- Wolf

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!