10
\$\begingroup\$

Does anyone know of any algorithms or can explain mathematically how brightness (EV) is executed in post-processing? Does it adjust the level of brightness/RBG/contrast for each pixel? Does it relate to the histogram?

What are the technicalities of exposure compensation for an underexposed image in post processing?

EDIT: In this question here, a link was posted. It has examples of changing the EV and it moves left/right. In Matt Grumm's answer, he states that each pixel is "multiplied" (which in my mind indicates that the histogram is moved up/down).

Can anyone explain why this is the case? (That EV changes from left to right)

\$\endgroup\$
8
  • \$\begingroup\$ Do you mean to restrict this question to those particular Adobe products, or are you interested in exposure adjustments in post-processing in general? \$\endgroup\$
    – mattdm
    Oct 12, 2012 at 12:41
  • \$\begingroup\$ possible duplicate of What does it mean to brighten an image? \$\endgroup\$
    – Itai
    Oct 12, 2012 at 12:47
  • 2
    \$\begingroup\$ I've read this twice and I'm still finding it quite a confusing question. Could you reword to strip out some of the more discursive parts and focus clearly on your core question? \$\endgroup\$ Oct 12, 2012 at 14:14
  • \$\begingroup\$ @mattdm Yeah, in general. Itai Kinda not really. :) Mark Whitaker Will do. (I was told that I can't at more than one person) \$\endgroup\$
    – BBking
    Oct 13, 2012 at 4:01
  • \$\begingroup\$ @Mark Whitaker Have I made it clearer yet? \$\endgroup\$
    – BBking
    Oct 22, 2012 at 1:43

5 Answers 5

8
\$\begingroup\$

I know that we get all excited about having digital cameras, but the fact is that we don't. We have analog cameras that happen to have a digital output format (and a lot of digital circuitry that is not directly related to the image as well).

Whenever an analog signal is converted to a digital signal, you introduce quantization noise. That is, it's very unlikely that the signal going into the conversion will exactly match the value of the digital number that comes out the other end — think of it as truncation or rounding errors.

When you do post-processing on a digital image file, the quantization noise the camera added is "baked in". It doesn't matter what bit depth you're working with in post, the data that you are working with has both the analog (well, quantum) noise components (thermal and shot noise, amplifier distortion, etc.) and the quantization noise of the camera's output. The quality of the base data is not perfect, so any computation done on the faulty data will result in faulty output. GIGO, as they say.

In-camera, on the other hand, you get the opportunity to amplify (or attenuate) the analog signal before quantization. That doesn't help at all with noise in the analog domain, but it does reduce the quantization noise at a given brightness level.

Let's say that you have an analog value of 4.4 whatchamacallits. If you shoot using ISO 100, our hypothetical "digital" camera will convert that to a digital value of exactly 4. If you choose to increase the apparent exposure in post, you're stuck working with the 4, which is truncated. If you increase the ISO in the camera (by less than a full stop), that 4.4 will be amplified by analog circuitry before it's converted to digital, and may result in a 1-higher digital value than the all-digital processing computes. A single-bit difference may not sound like much, but when you start accumulating all of the errors along the way in processing, a given pixel might be quite a long way from the values it ought to have. That's what noise is.

(There is also the fact that the camera "knows" its own response characteristics, and can account for them in processing. Lightroom, for instance, doesn't do camera-specific, ISO-based sensor noise subtraction. Cameras can, though not all do.)

\$\endgroup\$
2
  • \$\begingroup\$ Thanks Stan. Yeah, there is all types of noise in a photographic picture. So if you adjust the EV in PP, you also amplify that noise. Just as the ISO amplifies any noise. \$\endgroup\$
    – BBking
    Oct 13, 2012 at 4:13
  • 2
    \$\begingroup\$ Bumping ISO and EV both amplify noise, but I think what Stan is saying is that adjusting ISO upwards in camera is better than bumping the exposure in post-processing (because you are essentially amplifying the signal before the quantization noise is introduced in the A/D step). \$\endgroup\$
    – seanmc
    Oct 15, 2012 at 0:21
5
\$\begingroup\$

Is this the formula you are looking for?

RGB[c] = max( RGB[c] * pow(2,EV), RGBmax )

Which basically means that for each channel (of each pixel) of the RGB data, multiply it by 2^EV and then clip it to whatever the maximum value is for your data. For 8 bit color RGBmax will be 255, for 16 bit color it will be 65535, etc.

EV here is relative EV so EV+2.0 will multiply (brighten) every pixel by a factor of four and EV-2.0 will divide (darken) every pixel by a factor of four.

The formula itself doesn't depend on the histogram, but if you need to decide what Exposure Value to use to optimally adjust the picture then some sort of statistics would be done from the histogram to calculate EV.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ I believe RGB values already represent perceived brightness so your formula is incorrect. It would be correct for the values measured by the sensor (which is close to linear, see Matt's answer) but not for the already converted RGB values. (Try what happens if you apply your formula.) \$\endgroup\$
    – Szabolcs
    Aug 23, 2013 at 21:18
  • \$\begingroup\$ @Szabolcs, I thought the OP was asking for an algorithm to do EV compensation in post processing, no? I admit the question is not quite clear to me, but they are asking for math. \$\endgroup\$
    – Octopus
    Aug 24, 2013 at 4:58
  • \$\begingroup\$ Thanks for your answer! Do you have a link for that formulae so I can closer examine it? \$\endgroup\$
    – BBking
    Aug 26, 2013 at 0:38
  • 1
    \$\begingroup\$ @Octopus Yes, but my point was that your formula is incorrect if applied to RBG values. The RGB values are computed from the raw sensor data by taking the logarithm of the raw value (our perception is approximately logarithmic) and then rescaling the result linearly (which corresponds to setting the black point and the white point). (Plus some other things that Matt has mentioned.) Thus your formula is correct when applied to raw pixel values, but it is incorrect for RGB values. If you actually try to carry out the transformation on an image in practice, you'll see what I mean. \$\endgroup\$
    – Szabolcs
    Aug 28, 2013 at 15:34
  • \$\begingroup\$ Take a raw file, extract the data using dcraw with the -4 switch to ensure it won't do the log transformation itself, then try to perform a basic raw conversion yourself and apply an exposure compensation during the process. \$\endgroup\$
    – Szabolcs
    Aug 28, 2013 at 15:35
4
+50
\$\begingroup\$

N.B. the question was edited since Stan's answer to this addresses what is effectively a different question:

Does anyone know of any algorithms or can explain mathematically how brightness (EV) is executed in post-processing? Does it adjust the level of brightness/RBG/contrast for each pixel? Does it relate to the histogram?

What are the technicalities of exposure compensation for an underexposed image in post processing?

It can be a simple as multiplying all the pixel values (e.g. the brightness, contrast is not a term that applies to individual pixels) and applying an offset. If it is done after demosaicing then you simply multiply the red green and blue values by the same factor.

The process of exposure compensation is a little more complex in the context of RAW conversion, as camera sensors are inherently linear devices whilst most RAW converters apply a nonlinear tonecurve to try and emulate the contrasty S-curve you get with film.

Thus the best time to do exposure compensation is before this is applied. This basically means using your RAW converter's EC function, not waiting 'till you've exported the Photoshop as the nonlinear curve will almost certainly have been applied by then.

The situation is yet more complex as some RAW converters* used "twisted" colour profiles, which cause the hue/saturation get mapped to different values depending on intensity. This is done to produce more pleasing colours at the expense of accuracy, and can affect the results of exposure compensation.

Some RAW converters also offer tools to recover highlights and boost shadows. These make local adjustments (i.e. they take into account much more than individual pixel values). If you want to know the details of these algorithms you'll probably have to wait and hope a Lightroom developer shows up here.

* when I say "some RAW converters" I'm basically talking about Lightroom/ACR, as that's the only one I've studied, other advanced RAW converters probably do similar.

\$\endgroup\$
4
  • \$\begingroup\$ From what you know, are you able to demonstrate how multiplying the RGB value results in higher brightness? As in, does a pixel structure have values for colour and brightness? AS far as I know, you can multiply a pixel value to change it's colour too. I like the S-curve into. I know I'm asking specifically about an individual pixel but I understand more in involved with a picture as a whole. I understand interpolation is also involved. \$\endgroup\$
    – BBking
    Aug 21, 2013 at 23:54
  • 1
    \$\begingroup\$ @BBking RAW files contain only intensity (brightness) values, each pixel has a colour filter so you have alternating red, green and blue intensities. As camera sensors are linear devices, scaling the recorded values gives pretty much the same result as exposing the sensor for longer. After demosaicing images can be stored in a number of colour formats, the most common being RGB, where at each pixel the amount of red, green and blue light is recorded. Multiplying each of these values by the same factor increases the brightness, multiplying each value by a different amount changes the colour. \$\endgroup\$
    – Matt Grum
    Aug 22, 2013 at 13:08
  • \$\begingroup\$ 'As camera sensors are linear devices'... To be pedantic, camera sensors are 'almost linear' as ([you already pointed out])(photo.stackexchange.com/a/33986/6294). (I thought it was worth the mention, as the OP is also interested in the mathematical formulation of the problem). A good algorithm could in theory take into account the typical response of the sensor, even if working only with RGB values. \$\endgroup\$
    – Alberto
    Aug 23, 2013 at 13:25
  • \$\begingroup\$ @Alberto yes that's a good point, I should have said "approximately linear" but as my comment was already 598 characters long that would have taken it over 600 and would have necessitated splitting into two comments ;) \$\endgroup\$
    – Matt Grum
    Aug 23, 2013 at 16:22
4
\$\begingroup\$

Mathematically, the brightness of a matrix (image) is affected overall by acting on the CIE L* function value of the pixel hue. It's an arithmetical relationship. Add, subtract, multiply, and divide.

Again, mathematically, a transformation matrix (numerical) is anded to the existing matrix in pp. These can be made selectively to the subject or to the overall matrix (image).

Good exposure and bad exposure are arbitrary terms—so long as the illuminance range of the subject lies within the useful range of the camera sensor. The subject range can be broad or narrow to the extreme.

Note: The histogram is a visual aid that represents the relative distribution of illuminances in the image. It is linear. It has nothing to do with exposure, the reciprocal relationship of intensity and time, which is always represented logarithmically.

\$\endgroup\$
3
\$\begingroup\$

What are the technicalities of exposure compensation for an under exposed image in post processing?

Mere boosting of all the values in an image will increase all the values by an equal amount. This "linear" response is peculiar to digital images.

We don't perceive things that way and the resulting image will appear unnatural.

Analog (film emulsion) image appeared more natural as the response of a photographic emulsion more nearly resembles the response of the human visual system. References were made to an "S" shaped curve. That characteristic "S" shape is an analog response.

Compensating for the difference between our proportional human visual response and the linear digital response invites various means to harmonize the difference aesthetically.

There need be an effective way to provide a proportional compensation for the difference. That's the technicality.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.