Modify Automatic contrast command and Levels tool
Posted: Mon Jan 12, 2009 2:09 pm
XnView has an impressive set of Image Editing tools, which was the main reason for me to switch from IrfanView. However, these tools are poorly documented, so that I decided to try to figure out their precise working, using Photoshop as a reference (actually I used Photoshop Elements but I think that the different tools work the same in both programs). Here are my findings so far.
The XnView Image/Map/Automatic levels and the PhotoShop Auto Levels commands have precisely the same effect. They linearly and independently stretch the Red, Green, and Blue histograms so that the darkest pixel of the final image is always pure black while the lightest one is pure white. This maximizes the overall image contrast but usually changes the color balance. In some cases this last effect can be beneficial since it can remove unwanted color casts.
The XnView Image/Map/Automatic contrast command has precisely the same effect as moving the BlackPoint slider up to the leftmost non zero histogram value and the WhitePoint slider up to the rightmost non zero value in the Image/Adjust/Levels tool. This also applies to PhotoShop. However, and rather surprisingly, the effect of the XnView Automatic contrast and that of the PhotoShop Auto Contrast commands on an image can be quite different, as discussed below.
The XnView Image/Adjust/Levels tool displays a histogram that is precisely the same as the Luminosity histogram in Photoshop, where:
Luminosity = 0.3 * Red + 0.59 * Green + 0.11 * Blue.
However, the Levels tool in Photoshop does not display the Luminosity histogram but rather the "RGB" histogram, which is a superposition of individual histograms for the Red, Green, and Blue channels.
Therefore, if the BlackPoint slider is moved up to the leftmost non zero histogram value and the WhitePoint slider up to the rightmost non zero value, the results obtained with XnView and with PhotoShop are usually different. With XnView it is quite possible that the darkest and the lightest pixels with different color values transform to have the same colors. However, this does not happen with PhotoShop. Consider the following example:
The darkest pixels of an image have the following RGB and Luminosity values:
000,063,000, Luminosity=037
031,087,023, Luminosity=063
063,111,047, Luminosity=090
while the lightest include pure white (255,255,255, Luminosity=255).
In XnView the Levels histogram would extend from 037 to 255, so that the Automatic contrast command would map the input Luminosity 037 value to an output value of zero. Therefore, the considered pixels would transform to:
000,030,000, Luminosity=018
000,058,000, Luminosity=034
030,086,012, Luminosity=061
Note that in the first two input pixels the Red and Blue values are different while they are equal in the first two output pixels.
This shows that the XnView Automatic contrast command (and the Levels tool) can often lead to color posterization (different input color values become equal in the output). This does not happen in the corresponding PhotoShop tools since, for the considered example, the RGB histogram extends from 000 (there are 000 Red and Blue values in the first considered pixels) to 255, so that the Auto Contrast command has no effect whatsoever on the image.
Conclusion: I think that it would be advisable to modify the Image/Map/Automatic contrast command and the Image/Adjust/Levels tool showing the RGB histogram (as in PhotoShop) rather than the Luminosity histogram, since the present implementation tends to lose information in the darkest and lightest parts of the image by means of color posterization.
The XnView Image/Map/Automatic levels and the PhotoShop Auto Levels commands have precisely the same effect. They linearly and independently stretch the Red, Green, and Blue histograms so that the darkest pixel of the final image is always pure black while the lightest one is pure white. This maximizes the overall image contrast but usually changes the color balance. In some cases this last effect can be beneficial since it can remove unwanted color casts.
The XnView Image/Map/Automatic contrast command has precisely the same effect as moving the BlackPoint slider up to the leftmost non zero histogram value and the WhitePoint slider up to the rightmost non zero value in the Image/Adjust/Levels tool. This also applies to PhotoShop. However, and rather surprisingly, the effect of the XnView Automatic contrast and that of the PhotoShop Auto Contrast commands on an image can be quite different, as discussed below.
The XnView Image/Adjust/Levels tool displays a histogram that is precisely the same as the Luminosity histogram in Photoshop, where:
Luminosity = 0.3 * Red + 0.59 * Green + 0.11 * Blue.
However, the Levels tool in Photoshop does not display the Luminosity histogram but rather the "RGB" histogram, which is a superposition of individual histograms for the Red, Green, and Blue channels.
Therefore, if the BlackPoint slider is moved up to the leftmost non zero histogram value and the WhitePoint slider up to the rightmost non zero value, the results obtained with XnView and with PhotoShop are usually different. With XnView it is quite possible that the darkest and the lightest pixels with different color values transform to have the same colors. However, this does not happen with PhotoShop. Consider the following example:
The darkest pixels of an image have the following RGB and Luminosity values:
000,063,000, Luminosity=037
031,087,023, Luminosity=063
063,111,047, Luminosity=090
while the lightest include pure white (255,255,255, Luminosity=255).
In XnView the Levels histogram would extend from 037 to 255, so that the Automatic contrast command would map the input Luminosity 037 value to an output value of zero. Therefore, the considered pixels would transform to:
000,030,000, Luminosity=018
000,058,000, Luminosity=034
030,086,012, Luminosity=061
Note that in the first two input pixels the Red and Blue values are different while they are equal in the first two output pixels.
This shows that the XnView Automatic contrast command (and the Levels tool) can often lead to color posterization (different input color values become equal in the output). This does not happen in the corresponding PhotoShop tools since, for the considered example, the RGB histogram extends from 000 (there are 000 Red and Blue values in the first considered pixels) to 255, so that the Auto Contrast command has no effect whatsoever on the image.
Conclusion: I think that it would be advisable to modify the Image/Map/Automatic contrast command and the Image/Adjust/Levels tool showing the RGB histogram (as in PhotoShop) rather than the Luminosity histogram, since the present implementation tends to lose information in the darkest and lightest parts of the image by means of color posterization.