How to stretch the histogram without altering the color

0
597

A few weeks ago I published an article entitled “Histogram Right-Shifting and Color Reproduction” where I warned about the color reproduction problems caused by exposure correction during image processing.

However, shortly thereafter Guillermo Luijk through the Micro4Tercios forum alerted us that the concept I was addressing in my article is motivated by working with gamma-corrected images and should not be an intrinsic phenomenon of raw processing, but rather it is caused because most popular development tools do not process linear images but gamma-corrected ones.

That is, if a sensor has a linear behavior, after multiplying our image by a factor prior to gamma correction, the result will be an image equivalent to one that is more or less exposed, without observing “hue shifts” or alterations in the chromatic dimension of our image.

Unfortunately, we cannot approach this process with Adobe Photoshop (which is what most people use), because it cannot handle strictly linear images or processes. So the moment we introduce gamma correction to an image, it no longer behaves linearly, and therefore any adjustment on the image is not applied linearly across the tonal range, which distorts the color.

Similarly, we cannot make this type of adjustment on an image described in a particular color space, since it would be perceptually corrected, and any change is made based on the perceptual parameters of that color space, for example CIE Lab.

Guillermo has already extensively published and developed this concept on his website under the title Does Exposure Alter Color?, however, I found it interesting to contribute my own perspective on the solution:

How do we perform a histogram right-shift without harming the color?

For this, we will use two well-known tools: DCRAW and ImageMagick.

DCRAW allows us to create strictly linear images that are decontextualized from any color space:

dcraw -T -4 -o 0 DSC6252.NEF

Next, ImageMagick allows us to compute each channel by a factor. Testing with the “-evaluate multiply” parameter, a factor of 2 is equivalent to exposing the image +1EV and a factor of 4 is equivalent to +2EV. Conversely, the “-evaluate divide” parameter allows us to underexpose the equivalent of -1EV or -2EV using the respective factors.

Thus, to digitally “overexpose,” we use:

convert DSC6252.tiff -channel R -evaluate multiply 4 \
   -channel G -evaluate multiply 4 \
   -channel B -evaluate multiply 4 DSC6252-4.tiff

And if we want to “underexpose,” we use:

convert DSC6252.tiff -channel R -evaluate divide 4 \
   -channel G -evaluate divide 4 \
   -channel B -evaluate divide 4 DSC6252-4.tiff

Finally, to evaluate the image in perceptual terms, we must apply a gamma adjustment:

convert DSC6252-4.tiff gamma 2.2 DSC6252-4-2.2.tiff

At this point, we already have a gamma-corrected image that we can evaluate from our perception.

imagen lineallinealx2corregida gammareferencia 1EV

As we can see, at first glance the resulting image from our workflow, called “Gamma 2.2,” is apparently identical to its reference taken with a 1EV difference. But let us better examine the results in numbers….

Results

Starting from three images with a difference of +1EV and +2EV concluded, in view of the colorimetric analyses which are practically identical:

analisis derecheo del histogramaanalisis derecheo del histograma deltas

As we see, for two images with an exposure difference of 1EV we reach a maximum delta-e error of 0.55 and for 2EV of 0.89, and similarly to the delta error, the H (hue) error is practically negligible.

Conclusions

As we see, and contrary to what I stated in my other article, it IS possible to right-shift, or perform any other exposure adjustment during processing, without harming color reproduction, only that we must use alternative tools, applying intensity variations in linear mode to apply changes uniformly across the entire tonal range and not after a gamma adjustment which causes an intensity adjustment not to be applied equally across the tonal range and ends up distorting the chromatic dimension of our scene.

However, this technique is somewhat limited since working directly on Tiff files, noise problems can easily appear, for example when intensifying the signal. Nevertheless, I find it a very interesting technique to consider if we need to make “exposure adjustments” during processing, after having made a mistake with the exposure of a series of images, for example, in order to preserve colorimetric information.