"Automatic levels" adjustment wrongly implemented
Moderators: XnTriq, helmut, xnview
-
- Posts: 11
- Joined: Thu May 31, 2007 10:22 pm
"Automatic levels" adjustment wrongly implemented
Re: Image >> Map >> Automatic levels
What I think this was intended to do is the same as possible with Image >> Adjust >> Levels, but with automatic setup of black and white point according to minimum and maximum Y value found.
It, however, doesn't do that - after determining the present brightness extremes, it stretches the histogram in a linear fashion, just like the "contrast" adjustment would (the traditional software contrast and brightness adjustments work like that, which makes it no less wrong - a brightness adjustment that just shifts the histogram will have black end up being grey). In fact, one can take an image with black point = 0 and white point = 255, apply a negative contrast setting to it and then have "Automatic levels" restore pretty much the original condition. Manually applying "Levels" gives an entirely different result. (It would be complementary to a correctly-operating contrast adjustment.)
The basic underlying problem is the assumed brightness -> [0..255] quantisation mapping. This is not linear but in fact follows a log(1+a*x) law. The gamma function is an approximation for that, which explains why a monitor (with inverse gamma) can in principle restore the original brightness relations correctly.
What I think this was intended to do is the same as possible with Image >> Adjust >> Levels, but with automatic setup of black and white point according to minimum and maximum Y value found.
It, however, doesn't do that - after determining the present brightness extremes, it stretches the histogram in a linear fashion, just like the "contrast" adjustment would (the traditional software contrast and brightness adjustments work like that, which makes it no less wrong - a brightness adjustment that just shifts the histogram will have black end up being grey). In fact, one can take an image with black point = 0 and white point = 255, apply a negative contrast setting to it and then have "Automatic levels" restore pretty much the original condition. Manually applying "Levels" gives an entirely different result. (It would be complementary to a correctly-operating contrast adjustment.)
The basic underlying problem is the assumed brightness -> [0..255] quantisation mapping. This is not linear but in fact follows a log(1+a*x) law. The gamma function is an approximation for that, which explains why a monitor (with inverse gamma) can in principle restore the original brightness relations correctly.
-
- Author of XnView
- Posts: 44922
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: "Automatic levels" adjustment wrongly implemen
Yes, currently auto-levels is not like that. but perhaps a good idea to have a basic auto-levels like you said...stephan_g wrote:Re: Image >> Map >> Automatic levels
What I think this was intended to do is the same as possible with Image >> Adjust >> Levels, but with automatic setup of black and white point according to minimum and maximum Y value found.
Pierre.
-
- Posts: 251
- Joined: Sat Nov 17, 2007 7:53 am
- Location: Germany
Re: "Automatic levels" adjustment wrongly implemen
Sorry for the hijack. I am a bit puzzled by the german translation of this menu. Map is 'Farbänderung' (english 'Change colours'), 'Automatic levels' is 'Helligkeit automatisch einstellen' (english 'Set brightness automatically'). I am no professional, but what have colour operations to do with brightness and contrast? Is this translation really correct?stephan_g wrote:Re: Image >> Map >> Automatic levels
-
- Posts: 11
- Joined: Thu May 31, 2007 10:22 pm
See German xlation thread - das war mir nämlich auch schon aufgefallen. Evtl. dort einen Kommentar abgeben, ob die Vorschläge so passen.
-
- Posts: 11
- Joined: Thu May 31, 2007 10:22 pm
Re: "Automatic levels" adjustment wrongly implemen
I wonder what the current implementation would be good for. One is obviously not well advised to use it for real-life photos or scans, as the results can be highly peculiar.xnview wrote:Yes, currently auto-levels is not like that. but perhaps a good idea to have a basic auto-levels like you said...
-
- Posts: 698
- Joined: Thu Feb 09, 2006 10:18 am
- Location: Sweden
Re: "Automatic levels" adjustment wrongly implemen
I find the current implementation very useful for some images - giving excellent results - keep it. Maybe change the name if it is not a "real" auto-levels, but as I said, keep it by all means.stephan_g wrote:I wonder what the current implementation would be good for. One is obviously not well advised to use it for real-life photos or scans, as the results can be highly peculiar.
-
- Posts: 11
- Joined: Thu May 31, 2007 10:22 pm
One could call the current implementation "Stretch histogram (linear)" or somesuch, and "Automatic contrast" would become "Automatic contrast (linear)" for consistency. The "real" "Automatic levels" function would need to go into the "Adjust" submenu anyway, where the manual version already resides.
While we're at it, one should think about "new-school" brightness and contrast adjustments in addition to the "classic" linear ones (in analogy to the levels thing). The latter may still have their uses, but they shouldn't be the primary "brightness" and "contrast" adjustments any more - these days, we know better.
While we're at it, one should think about "new-school" brightness and contrast adjustments in addition to the "classic" linear ones (in analogy to the levels thing). The latter may still have their uses, but they shouldn't be the primary "brightness" and "contrast" adjustments any more - these days, we know better.
-
- Author of XnView
- Posts: 44922
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
What do you think by "new-school" brightness and contrast adjustments?stephan_g wrote:While we're at it, one should think about "new-school" brightness and contrast adjustments in addition to the "classic" linear ones (in analogy to the levels thing). The latter may still have their uses, but they shouldn't be the primary "brightness" and "contrast" adjustments any more - these days, we know better.
Do you have a picture sample where the current implementation doesn't work well?stephan_g wrote:I wonder what the current implementation would be good for. One is obviously not well advised to use it for real-life photos or scans, as the results can be highly peculiar.xnview wrote:Yes, currently auto-levels is not like that. but perhaps a good idea to have a basic auto-levels like you said...
EDITED: The auto levels that you want is Equalize function (i think)
Pierre.
-
- Posts: 884
- Joined: Sun Apr 10, 2005 4:29 pm
-
- Posts: 251
- Joined: Sat Nov 17, 2007 7:53 am
- Location: Germany
-
- Posts: 11
- Joined: Thu May 31, 2007 10:22 pm
There is a utility called "JPG-Illuminator" which was written because common image editing tools proved to be unable to correct the exposure on a real-life underexposed image. The discussion leading to this is highly interesting but unfortunately in German.
The classic "oldschool" brightness adjustment, as it's been implemented for many years, works by shifting the (r,g,b) values by a certain amount, assuming that
r,g,b ~ log(light intensity)
That this assumption does not apply can easily be shown - suppose you have black (0,0,0), a very dark grey (10,10,10) and middle grey (192,192,192), then "brightening" this may result in a slightly darker middle grey, slightly brighter middle grey and plain white. How likely is that to happen in real life? It gets even clearer when you look at the effect on colors - (40,0,0) is a dark but very saturated red, (140,100,100) much brighter but also much less saturated. This is why any attempt at exposure correction using a "classic" brightness control will not give sensible results. Gamma adjustment already works better as it leaves black point and white point constant, but AFAIK still is not "it".
I am not an expert in terms of image processing, so can only guess how "Levels" might work, but perhaps it works in HSL color space and assumes a monitor with gamma=2.2. (It gets more complicated when you want to brighten up a JPEG image, since JPEG tends to de-saturate darker parts. Besides, digital cameras tend to mimic a "film-like" behavior. For a utility like XnView, however, an algorithm assuming an ideal monitor should be plenty good enough.)
So maybe the problem is two-fold after all - incorrect quantisation function and directly operating in RGB color space.
The classic "oldschool" brightness adjustment, as it's been implemented for many years, works by shifting the (r,g,b) values by a certain amount, assuming that
r,g,b ~ log(light intensity)
That this assumption does not apply can easily be shown - suppose you have black (0,0,0), a very dark grey (10,10,10) and middle grey (192,192,192), then "brightening" this may result in a slightly darker middle grey, slightly brighter middle grey and plain white. How likely is that to happen in real life? It gets even clearer when you look at the effect on colors - (40,0,0) is a dark but very saturated red, (140,100,100) much brighter but also much less saturated. This is why any attempt at exposure correction using a "classic" brightness control will not give sensible results. Gamma adjustment already works better as it leaves black point and white point constant, but AFAIK still is not "it".
I am not an expert in terms of image processing, so can only guess how "Levels" might work, but perhaps it works in HSL color space and assumes a monitor with gamma=2.2. (It gets more complicated when you want to brighten up a JPEG image, since JPEG tends to de-saturate darker parts. Besides, digital cameras tend to mimic a "film-like" behavior. For a utility like XnView, however, an algorithm assuming an ideal monitor should be plenty good enough.)
So maybe the problem is two-fold after all - incorrect quantisation function and directly operating in RGB color space.
-
- XnThusiast
- Posts: 2010
- Joined: Wed Mar 17, 2004 8:33 pm
- Location: Sarasota Florida
-
- Moderator & Librarian
- Posts: 6387
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
xnview wrote:What do you think by "new-school" brightness and contrast adjustments?stephan_g wrote:While we're at it, one should think about "new-school" brightness and contrast adjustments in addition to the "classic" linear ones (in analogy to the levels thing). The latter may still have their uses, but they shouldn't be the primary "brightness" and "contrast" adjustments any more - these days, we know better.
Ron Bigelow ([url=http://www.ronbigelow.com/articles/shadow/shadow-highlight1/shadow-highlight1.htm]Shadow/Highlight – Part I[/url] » Data Lost to Tonal Curves) wrote:When a digital image is taken, a certain amount of information is captured. However, this information is not in a format that is directly usable. It needs to be processed in order for that information to become a usable image. However, there are different ways in which that information can be processed. One thing that is common to all these ways of processing the information is that tonal curves are used. Without the application of tonal curves, the data is so dark that it is barely recognizable. Figure 11 shows an image before the application of a tonal curve.
The problem is that many of the tonal curves that are used clip the data. This will result in lost detail in the shadows, the highlights, or both. Figures 12 and 13 show the effect of two different tonal curves on the highlight detail of the spray from a wave. In Figure 12, the highlight detail is mostly lost. By selecting a different tonal curve, the highlight detail was recovered as shown in Figure 13.
The problem is that the most commonly used shadow and highlight recovery techniques do not allow a photographer to access the data that was clipped due to the application of a tonal curve. However, some of the more advanced shadow and highlight recovery techniques do allow a photographer to access this data.
- O'Reilly Digital Media Blog – Inside Aperture
- Kevin Moloney: Perfesser Kev's Photoshop Tips
- Krešimir Matković: Tone Mapping Techniques and Color Image Difference in Global Illumination » Minimum Information Loss Methods
- Anil Kokaram: 1E8 Introduction to Electrical Engineering » Handouts