"Automatic levels" adjustment wrongly implemented

Bugs found in XnView Classic. Please report only one bug per topic!

Moderators: XnTriq, helmut, xnview

stephan_g
Posts: 11
Joined: Thu May 31, 2007 10:22 pm

"Automatic levels" adjustment wrongly implemented

Post by stephan_g »

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.
User avatar
xnview
Author of XnView
Posts: 44470
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: "Automatic levels" adjustment wrongly implemen

Post by xnview »

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.
Yes, currently auto-levels is not like that. but perhaps a good idea to have a basic auto-levels like you said...
Pierre.
pic_viewer
Posts: 251
Joined: Sat Nov 17, 2007 7:53 am
Location: Germany

Re: "Automatic levels" adjustment wrongly implemen

Post by pic_viewer »

stephan_g wrote:Re: Image >> Map >> Automatic levels
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
Posts: 11
Joined: Thu May 31, 2007 10:22 pm

Post by stephan_g »

See German xlation thread - das war mir nämlich auch schon aufgefallen. Evtl. dort einen Kommentar abgeben, ob die Vorschläge so passen.
stephan_g
Posts: 11
Joined: Thu May 31, 2007 10:22 pm

Re: "Automatic levels" adjustment wrongly implemen

Post by stephan_g »

xnview wrote:Yes, currently auto-levels is not like that. but perhaps a good idea to have a basic auto-levels like you said...
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.
User avatar
Troken
Posts: 698
Joined: Thu Feb 09, 2006 10:18 am
Location: Sweden

Re: "Automatic levels" adjustment wrongly implemen

Post by Troken »

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.
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
Posts: 11
Joined: Thu May 31, 2007 10:22 pm

Post by stephan_g »

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.
User avatar
xnview
Author of XnView
Posts: 44470
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

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.
What do you think by "new-school" brightness and contrast adjustments?
stephan_g wrote:
xnview wrote:Yes, currently auto-levels is not like that. but perhaps a good idea to have a basic auto-levels like you said...
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.
Do you have a picture sample where the current implementation doesn't work well?

EDITED: The auto levels that you want is Equalize function (i think)
Pierre.
User avatar
Drahken
Posts: 884
Joined: Sun Apr 10, 2005 4:29 pm

Post by Drahken »

"New school", "we know better"???
*Has no idea what stephan_g is talking about.*
pic_viewer
Posts: 251
Joined: Sat Nov 17, 2007 7:53 am
Location: Germany

Post by pic_viewer »

xnview wrote:The auto levels that you want is Equalize function (i think)
(German 'Ausgleichen'). I have yet to see one single picture where this function does something useful, i.e. does not make the pic look worse. Completely obsolete, IMHO.
stephan_g
Posts: 11
Joined: Thu May 31, 2007 10:22 pm

Post by stephan_g »

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.
User avatar
JohnFredC
XnThusiast
Posts: 2010
Joined: Wed Mar 17, 2004 8:33 pm
Location: Sarasota Florida

Post by JohnFredC »

I always have to switch from XnView to another tool to adjust exposure.

Improved exposure control would be wonderful!!!
John
User avatar
XnTriq
Moderator & Librarian
Posts: 6368
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Post by XnTriq »

xnview wrote:
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.
What do you think by "new-school" brightness and contrast adjustments?
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.