Severe contrast enhancements: on 45% rule — and cats

Started Jun 28, 2013 | Discussions
ilza
Forum MemberPosts: 74
Like?
Severe contrast enhancements: on 45% rule — and cats
Jun 28, 2013

There are 3 ways to perform global contrast enhancement/attenuation (or, what is the same, “apply a curve” to an image):

  1. The most stupid one: apply the curve separately to R,G,B channels. This leads to significant color shifts. IIUC, this is what Gimp is doing.
  2. Split the image into Brightness+Chromaticity components, apply the curve to the brightness, keeping Chromaticity as it was. (This still leads to unnatural colors.) I expect that most of reasonable image manipulation programs work this way. If brightness is actually luminosity, this means that the curve is applied to max(R,G,B), then the other two of RGB channels are changed proportionally.
  3. Do as in the first variant, then take Brightness-Hue-Saturation, and replace the hue by its initial value. I've heard that Capture One works this way. This still leads to unnatural colors. This is equivalent to applying the curve to the min/max of RGB, then tuning the intermediate value so that the hue is preserved.

Obviously, one can rewrite the second variant as: apply curves to R,G,B, then keep the new brightness, and put back the old saturation and hue. Likewise, the third variants keeps the new brightness and saturation, and keeps old hue.

Then there are the ways invented by the tone mapping people. (Recall that tone mapping is the procedure opposite to what is called HDR in popular culture: they take a natural [hence high dynamic range] image, and want to decrease the contrast in such a way that the image continues to look natural).

For example, look what is done to saturation by the last paragraph of Section 5 of Gradient Domain High Dynamic Range Compression. I tried to understand what kind of effect they want to create by this, remembering that the dynamic range is strongly reduced in what is done by the rest of their algorithm. My conclusion was that essentially, the saturation becomes the weighted geometric mean of the initial saturation, and the saturation after applying algorithm separately to R,G,B.

After this conclusion, one can apply the latter method of working with saturation to other algorithm of manipulation of contrast. So I started to do experiments applying curves naively, then restoring hue and trying mixes of the new saturation with the initial one.

My conclusions? Arithmetic mean works better than geometric one, and the correct weight of the initial saturation is 45%. In GIMP, one can easily do it the following way:

  • Triplicate the layer;
  • (optional) call two top layers “saturation” and “hue”;
  • change their ‘Mode’ accordingly;
  • set opacity of the “saturation” layer to 45%;
  • apply curve (or Levels) to the lowest layer.

So this is the “45% rule”. Which brings us to cats.

Many people already know the wonders of “find a cat” challenges; if you do not, I will try not to spoil the fun. There are plenty of them googlable; here is one (sorry, I could not find a proper attribution):

Find a cat here.

Myself, I’m in the category of people who can’t find it in 10min (even after seeing the place it is in highlighted, and arrows going to ears/eyes/etc). So I decide that it is a good candidate to check contrast enhancement algorithms. Here is the result of smart upscaling and 3× contrast enhancement (with 45% rule): Enhanced Cat (I did promise to have no spoilers!).

After seeing this, I do not have any problem to recognize the cat on the initial image. Unfortunately, when I tried it on a couple of people, it does not help them to find the cat… But at least, they had no doubts when pointed into the correct place on the image.

So my questions:

  • Do you know better algorithms to treat colors while doing severe contrast manipulations?
  • Can you enhance the contrast of the cat image so that it helps people find a cat there?
  • Do you have any ideas how would one try to do something similar with local contrast manipulations?
Babine
Veteran MemberPosts: 5,380
Like?
In CS6 ...
In reply to ilza, Jun 28, 2013

Duplicate image, Image/Apply Image ( Red channel, Invert box checked, Exclusion blend mode, 100% opacity). With the duplicate layer active, check out the effect that Multiply or Liner Burn blend modes have with your quest.

-- hide signature --

Cheers.
Gary
http://forums.dpreview.com/Galleries/8298604696/photos
http://www.pbase.com/pictek

Since changing my car horn to gun shot sounds... people move out of the way much faster now.

Reply   Reply with quote   Complain
Tom Axford
Senior MemberPosts: 1,220
Like?
Changing contrast without distorting hue and saturation
In reply to ilza, Jun 28, 2013

I sympathise with your frustration.

I spent a couple of years puzzling over how to apply a tone curve to an image without distorting the colours (both hue and saturation). After doing quite a lot of reading about colour models and experimenting, initially in Photoshop, later in GIMP (I have given up using Photoshop), I found a method of doing it, which is described here .

My method is mathematically correct, assuming I have correctly guessed what the various tools in GIMP do (unfortunately, I have not found any mathematical definition of the tools in GIMP, or in Photoshop for that matter, but the basic ones seem fairly obvious). The hue and saturation of every pixel is preserved, no matter how extreme the changes to the tone curve.

However, the method is a little tedious to apply (although you soon get used to doing it). It would be much preferable if GIMP implemented it directly in the tools that operate on the tone curve (Brightness-Contrast, Levels, Curves, etc.). In fact, it would be a minor change to the program code to implement it. I'm sure it will happen sometime in the future, let's hope sooner rather than later.

By the way, I'm not sure that this helps in finding the cat!

Reply   Reply with quote   Complain
lylejk
Forum ProPosts: 21,225Gear list
Like?
Found the cat.
In reply to ilza, Jun 28, 2013

Applied low frequence even (gives an HDR apparence but softens some details) and enhanced details Script-fu (brings out details) but didn't still see the cat.   Then all of the sudden I did.   lol

Don't think, at this tiny resolution, enhancement techniques would help though.  

-- hide signature --
 lylejk's gear list:lylejk's gear list
Leica V-LUX 1 Sony Cyber-shot DSC-W7
Reply   Reply with quote   Complain
gwlaw99
Senior MemberPosts: 1,111
Like?
Re: Severe contrast enhancements: on 45% rule — and cats
In reply to ilza, Jun 28, 2013

Would converting to LAB mode and only applying contrast enhancements to the L channel work?

Reply   Reply with quote   Complain
Ralph Ramirez
Veteran MemberPosts: 6,607
Like?
Re: Found the cat.
In reply to lylejk, Jun 28, 2013

Lyle, I couldn't find the darn thing but the area you selected I looked at but didn't magnify it enough.  I had given up, thanks for showing the location..........Ralph

Reply   Reply with quote   Complain
lylejk
Forum ProPosts: 21,225Gear list
Like?
Re: Found the cat.
In reply to Ralph Ramirez, Jun 28, 2013

Attention to details Railph; attention to details.   lololol

-- hide signature --
 lylejk's gear list:lylejk's gear list
Leica V-LUX 1 Sony Cyber-shot DSC-W7
Reply   Reply with quote   Complain
Tom Axford
Senior MemberPosts: 1,220
Like?
LAB mode does not preserve the colours
In reply to gwlaw99, Jun 28, 2013

gwlaw99 wrote:

Would converting to LAB mode and only applying contrast enhancements to the L channel work?

Unfortunately this doesn't work in general, because of the way that L (luminance, lightness or luminosity) is defined, which is something like:

L = 0.21R + 0.72G + 0.07B

So pure white (1.0,1.0,1.0) for (R,G,B) has a luminance of 0.21x1.0 + 0.72x1.0 + 0.07x1.0 = 1.0

But other colours will have luminance less than 1.0. For example, a bright blue (0.2,0.4,1.0) has a luminance of only 0.21x0.2 + 0.72x0.4 + 0.07x1.0 = 0.4

If you choose to apply a curve that tries to raise a luminance of 0.4 to a higher value, it can't be done to our bright blue colour because the blue component is already 1.0, which is the maximum that can be represented. So, the blue channel will be clipped, which changes the colour. In fact, this is likely to happen to any colours that are close to the maximum brightness than can be represented, if the tone curve is anywhere raised above its initial value.

Sorry about the maths, but I can't think of any other way to explain it.

Reply   Reply with quote   Complain
Deleted1929
Forum ProPosts: 13,050
Like?
Re: LAB mode does not preserve the colours
In reply to Tom Axford, Jun 29, 2013

The L in LAB is not a linear mix of RGB.  It's considerably more complex.

The site I generally refer to for this sort of thing is Bruce Lindbloom's website, however Wikipedia has a page on it :

https://en.wikipedia.org/wiki/Lab_color_space

http://www.brucelindbloom.com/  ( look under "Math" ).

To get the L component you need first the Y component from the XYZ space.  That Y component is a linear mix of RGB.  However the L component is a non-linear function of Y.

LAB is designed to give an L component that is a reasonable representation of human perceived tonality.  So the L component actually makes a pretty good B&W version of an image.

However changing just L values ( leaving AB values unaltered ) and then converting back to RGB does change hue and saturation.

I find the HSV space most useful for preserving color, although no space is perfect at this in my experience.  In GIMP you can mix a layer using Value mode ( the V component referred to in HSV ).  This is useful for avoiding the worst of color shifts.

-- hide signature --

StephenG

Reply   Reply with quote   Complain
Charles2
Senior MemberPosts: 2,090
Like?
Two great tools for these operations
In reply to ilza, Jun 29, 2013

Two great tools for these operations:

Picture Window Pro gives you the three HSV curves and the three HSL curves, as well as the three RGB curves. PWP just emerged from a thorough beta testing of version 7, so now is a good time to take it for a trial drive.

Raw Therapee gives you the three LAB curves as well as exquisite control over exposure (.01 stop) and also over a Black Point slider. Most of its operations work on TIFs and JPGs; the program demosaics virtually all Bayer camera raw files.

For practical work, the discussion of the HSV and HSL spaces by Norman Koren is helpful. He summarizes:

  • Darkening in HSV reduces saturation. Darkening in HSL increases saturation when L > 0.5.
  • Lightening in HSV increases saturation. Lightening in HSL reduces saturation when L > 0.5.

So, for example, if you want the lighter portion of the image to become "richer" and to pop, apply HSL-L contrast, favoring the darkening point, on an upper portion of the curve.

As for adjusting the R, G, and B curves, this method can be a subtle way to get the color balance you need. Also, digital emulations of films like Provia and Portra are available as sets of R,G,B manipulations, which you can apply in PWP then adjust for a specific image.

Reply   Reply with quote   Complain
Tom Axford
Senior MemberPosts: 1,220
Like?
Re: LAB mode does not preserve the colours
In reply to Deleted1929, Jun 29, 2013

sjgcit wrote:

The L in LAB is not a linear mix of RGB. It's considerably more complex.

The site I generally refer to for this sort of thing is Bruce Lindbloom's website, however Wikipedia has a page on it :

https://en.wikipedia.org/wiki/Lab_color_space

http://www.brucelindbloom.com/ ( look under "Math" ).

To get the L component you need first the Y component from the XYZ space. That Y component is a linear mix of RGB. However the L component is a non-linear function of Y.

LAB is designed to give an L component that is a reasonable representation of human perceived tonality. So the L component actually makes a pretty good B&W version of an image.

However changing just L values ( leaving AB values unaltered ) and then converting back to RGB does change hue and saturation.

I find the HSV space most useful for preserving color, although no space is perfect at this in my experience. In GIMP you can mix a layer using Value mode ( the V component referred to in HSV ). This is useful for avoiding the worst of color shifts.

-- hide signature --

StephenG

Stephen,

Thanks for your comments.

As usual, I cannot disagree with anything you say here. The formula I gave for L is a crude approximation that ignores the non-linearity.  However, the accuracy of this formula does not affect my argument, but you are correct in suggesting that I should really have mentioned that it was a  crude approximation.

I think your final statement is unduly conservative. In my (admittedly limited) experience, changing only the V values in HSV does more than just 'avoiding the worst colour shifts', it avoids all noticeable colour shifts, to my eyes at least. Are you aware of any specific examples where changing only V shows any obvious colour shifts?

Tom.

Reply   Reply with quote   Complain
VicC
Senior MemberPosts: 1,274Gear list
Like?
Re: Easy way
In reply to Charles2, Jun 29, 2013

Easy? Vic

Reply   Reply with quote   Complain
tom60634
Senior MemberPosts: 1,836Gear list
Like?
Re: Severe contrast enhancements: on 45% rule — and cats
In reply to ilza, Jun 29, 2013

ilza wrote:

There are 3 ways to perform global contrast enhancement/attenuation (or, what is the same, “apply a curve” to an image):

  1. The most stupid one: apply the curve separately to R,G,B channels. This leads to significant color shifts. IIUC, this is what Gimp is doing.
  2. Split the image into Brightness+Chromaticity components, apply the curve to the brightness, keeping Chromaticity as it was. (This still leads to unnatural colors.) I expect that most of reasonable image manipulation programs work this way. If brightness is actually luminosity, this means that the curve is applied to max(R,G,B), then the other two of RGB channels are changed proportionally.
  3. Do as in the first variant, then take Brightness-Hue-Saturation, and replace the hue by its initial value. I've heard that Capture One works this way. This still leads to unnatural colors. This is equivalent to applying the curve to the min/max of RGB, then tuning the intermediate value so that the hue is preserved.

Obviously, one can rewrite the second variant as: apply curves to R,G,B, then keep the new brightness, and put back the old saturation and hue. Likewise, the third variants keeps the new brightness and saturation, and keeps old hue.

Then there are the ways invented by the tone mapping people. (Recall that tone mapping is the procedure opposite to what is called HDR in popular culture: they take a natural [hence high dynamic range] image, and want to decrease the contrast in such a way that the image continues to look natural).

For example, look what is done to saturation by the last paragraph of Section 5 of Gradient Domain High Dynamic Range Compression. I tried to understand what kind of effect they want to create by this, remembering that the dynamic range is strongly reduced in what is done by the rest of their algorithm. My conclusion was that essentially, the saturation becomes the weighted geometric mean of the initial saturation, and the saturation after applying algorithm separately to R,G,B.

After this conclusion, one can apply the latter method of working with saturation to other algorithm of manipulation of contrast. So I started to do experiments applying curves naively, then restoring hue and trying mixes of the new saturation with the initial one.

My conclusions? Arithmetic mean works better than geometric one, and the correct weight of the initial saturation is 45%. In GIMP, one can easily do it the following way:

  • Triplicate the layer;
  • (optional) call two top layers “saturation” and “hue”;
  • change their ‘Mode’ accordingly;
  • set opacity of the “saturation” layer to 45%;
  • apply curve (or Levels) to the lowest layer.

So this is the “45% rule”. Which brings us to cats.

Many people already know the wonders of “find a cat” challenges; if you do not, I will try not to spoil the fun. There are plenty of them googlable; here is one (sorry, I could not find a proper attribution):

Find a cat here.

1. open in camera raw and assign a color profile - for the web sRGB is the obvious choice.

2. adjust grey point, exposure, white point, black point.

3. open in photoshop to make final adjustments.

4. save for web

I tried to emphasize the cat while keeping the file looking like a photograph.

Myself, I’m in the category of people who can’t find it in 10min (even after seeing the place it is in highlighted, and arrows going to ears/eyes/etc). So I decide that it is a good candidate to check contrast enhancement algorithms. Here is the result of smart upscaling and 3× contrast enhancement (with 45% rule): Enhanced Cat (I did promise to have no spoilers!).

After seeing this, I do not have any problem to recognize the cat on the initial image. Unfortunately, when I tried it on a couple of people, it does not help them to find the cat… But at least, they had no doubts when pointed into the correct place on the image.

So my questions:

  • Do you know better algorithms to treat colors while doing severe contrast manipulations?
  • Can you enhance the contrast of the cat image so that it helps people find a cat there?
  • Do you have any ideas how would one try to do something similar with local contrast manipulations?
 tom60634's gear list:tom60634's gear list
Olympus OM-D E-M5
Reply   Reply with quote   Complain
knickerhawk
Veteran MemberPosts: 3,224
Like?
Re: LAB mode does not preserve the colours
In reply to Deleted1929, Jun 30, 2013

sjgcit wrote:

The L in LAB is not a linear mix of RGB. It's considerably more complex.

The site I generally refer to for this sort of thing is Bruce Lindbloom's website, however Wikipedia has a page on it :

https://en.wikipedia.org/wiki/Lab_color_space

http://www.brucelindbloom.com/ ( look under "Math" ).

To get the L component you need first the Y component from the XYZ space. That Y component is a linear mix of RGB. However the L component is a non-linear function of Y.

LAB is designed to give an L component that is a reasonable representation of human perceived tonality. So the L component actually makes a pretty good B&W version of an image.

However changing just L values ( leaving AB values unaltered ) and then converting back to RGB does change hue and saturation.

What do you mean that it changes hue?  If I change L I see virtually no change in the H value of HSB in Photoshop as long as I don't go out of gamut.  The B and S do shift as expected.

I find the HSV space most useful for preserving color, although no space is perfect at this in my experience. In GIMP you can mix a layer using Value mode ( the V component referred to in HSV ). This is useful for avoiding the worst of color shifts.

Since HSV and LAB are "cousins," why is it you think that changing V is going to be any more neutral with regard to color shifts than changing L?  Aren't they basically the same?

It seems like kind of an odd argument that adjusting L in LAB "does not preserve the colors".  By definition it does.  The problem comes when one has to return to the limitations imposed by the color space you're outputting to.  However, as long as you stay within the gamut of your output color space, L adjustments should be as color neutral as you could hope for.  Certainly as neutral as anything you're going to be able to do in an RGB space.

Reply   Reply with quote   Complain
Tom Axford
Senior MemberPosts: 1,220
Like?
Re: LAB mode does not preserve the colours
In reply to knickerhawk, Jun 30, 2013

knickerhawk wrote:

It seems like kind of an odd argument that adjusting L in LAB "does not preserve the colors". By definition it does. The problem comes when one has to return to the limitations imposed by the color space you're outputting to. However, as long as you stay within the gamut of your output color space, L adjustments should be as color neutral as you could hope for. Certainly as neutral as anything you're going to be able to do in an RGB space.

Unfortunately, there is a fly in the ointment.

Perhaps the best way to see the problem is through an example. Take the following image, which is a bright red in which the R channel is at the maximum (255):

Convert this image to LAB mode and then change the L component to maximum everywhere (i.e. make the L layer a pure white layer) and convert back to RGB. The result is (according to GIMP):

It has clearly changed colour. Why?

The problem is that the luminosity of the original colour is well below the maximum luminosity, but when you try to raise its luminosity, the red channel inevitably gets clipped (because the red channel is already at the maximum possible), causing the colour shift.

Reply   Reply with quote   Complain
knickerhawk
Veteran MemberPosts: 3,224
Like?
Re: LAB mode does not preserve the colours
In reply to Tom Axford, Jun 30, 2013

Tom Axford wrote:

knickerhawk wrote:

It seems like kind of an odd argument that adjusting L in LAB "does not preserve the colors". By definition it does. The problem comes when one has to return to the limitations imposed by the color space you're outputting to. However, as long as you stay within the gamut of your output color space, L adjustments should be as color neutral as you could hope for. Certainly as neutral as anything you're going to be able to do in an RGB space.

Unfortunately, there is a fly in the ointment.

Unfortunately, the same fly is in your ointment too.

Perhaps the best way to see the problem is through an example. Take the following image, which is a bright red in which the R channel is at the maximum (255):

Convert this image to LAB mode and then change the L component to maximum everywhere (i.e. make the L layer a pure white layer) and convert back to RGB. The result is (according to GIMP):

It has clearly changed colour. Why?

The problem is that the luminosity of the original colour is well below the maximum luminosity, but when you try to raise its luminosity, the red channel inevitably gets clipped (because the red channel is already at the maximum possible), causing the colour shift.

I already acknowledged this issue. LAB is particularly "dangerous" in the sense that you're working with a much bigger color space than most RGB color spaces.  The problem of channel clipping, though, is certainly not unique to LAB, so it's rather unfair to use this example as some kind of "proof" that there is a problem with working with LAB to adjust contrast.  If I take your red sample above and do a brightness push in RGB, guess what?  It turns yellowish ochre just like it did in LAB.

Again, contrast adjustments made in the L channel are as neutral with respect to color shifts as you could hope for.  I've seen it time and time again.  When I boost contrast in RGB, I get subtle unwanted shifts in hue and often more saturation than is desired.  Blue sky shifts to red.  Grass  turns lime green.  Often, I can minimize the unwanted impact by doing a luminosity blend in RGB.  However, the same effect as a luminosity blend is achieved in LAB by adjusting the L channel.  Depending on the image, LAB is often the best solution for making these kinds of adjustments.

-- hide signature --
Reply   Reply with quote   Complain
Tom Axford
Senior MemberPosts: 1,220
Like?
HSV works better than either RGB or LAB
In reply to knickerhawk, Jul 1, 2013

For adjusting the tone curve, HSV works better than either RGB or LAB.

The V channel may be adjusted (even to extremes) without causing colour shifts and without the risk of channel clipping on conversion back to RGB.

Reply   Reply with quote   Complain
knickerhawk
Veteran MemberPosts: 3,224
Like?
Re: HSV works better than either RGB or LAB
In reply to Tom Axford, Jul 1, 2013

Tom Axford wrote:

For adjusting the tone curve, HSV works better than either RGB or LAB.

The V channel may be adjusted (even to extremes) without causing colour shifts and without the risk of channel clipping on conversion back to RGB.

Well, I use Photoshop, so I don't have the option of converting to HSV as you do in GIMP.  However, it's my understanding that applying a luminosity blend in RGB (which is what I normally do if I'm not otherwise working in LAB), also achieves the goal without affecting color.  There are times (for instance with already reasonably contrasty, colorful images)  that the relative linear nature of the L channel in LAB can allow you to do more targeted curve adjustments.  Since I've never worked with HSV I can't say, but isn't the V channel relatively non-linear?  If so, it might make it somewhat more difficult to control the affects of the curve adjustment.

Different strokes for different folks (using different tools)...

-- hide signature --
Reply   Reply with quote   Complain
Antioch
Senior MemberPosts: 1,820
Like?
Re:Could somebody draw in the cat ! I do not see it !
In reply to ilza, Jul 1, 2013

Regards

Reply   Reply with quote   Complain
Tom Axford
Senior MemberPosts: 1,220
Like?
Re: HSV works better than either RGB or LAB
In reply to knickerhawk, Jul 2, 2013

knickerhawk wrote:

Tom Axford wrote:

For adjusting the tone curve, HSV works better than either RGB or LAB.

The V channel may be adjusted (even to extremes) without causing colour shifts and without the risk of channel clipping on conversion back to RGB.

Well, I use Photoshop, so I don't have the option of converting to HSV as you do in GIMP. However, it's my understanding that applying a luminosity blend in RGB (which is what I normally do if I'm not otherwise working in LAB), also achieves the goal without affecting color. There are times (for instance with already reasonably contrasty, colorful images) that the relative linear nature of the L channel in LAB can allow you to do more targeted curve adjustments. Since I've never worked with HSV I can't say, but isn't the V channel relatively non-linear? If so, it might make it somewhat more difficult to control the affects of the curve adjustment.

Different strokes for different folks (using different tools)...

-- hide signature --

That's a very interesting question you raise about whether a curve adjustment in LAB produces a more pleasing result than a similar curve adjustment in HSV. I do not have enough experience of using both to even give an opinion (I almost always use HSV because it is convenient for me and it does avoid clipping).

The mathematical definition of V is simply the maximum of R, G and B; whereas L is a much more complex formula chosen to approximate to the luminosity as seen by the human eye. I would agree with you that, on the face of it, using L feels to be the more sensible thing to do (provided you are careful to avoid clipping). In practice, however, ... I don't know.

Reply   Reply with quote   Complain
Keyboard shortcuts:
FForum MMy threads