# How can I automatically get a (approximate) Lux value from overexposed and underexposed pictures?

As you will soon understand, I am not a photographer. For research in a completely different field, I am interested in estimating, even with a large approximation, the brightness of the environment in a series of pictures.

I won't enter the lux vs illuminance vs luminance topic - let's say I am OK with anyone of these. So, as far as I understand:

EV to Lux

There are tables like this that, maybe with huge uncertainty, let you pass from EV to Lux, and you can get EV from exposure time and f-number. Fine!

1. What about ISO?

These tables work with `ISO = 100`. From my understanding, if I have `ISO = 200`, I just need to add 1 to my EV, thus looking at the row below. Is this correct?

2. What about pictures not exposed correctly?

If what I said in `1` is correct, I should be able to infer Lux by simply using ISO, exposure time and f-number. However, I could take two pictures, varying a single parameter between the two, and I would get two different Lux values even if the scene was the same.

For my application, I think another parameter should come into play, which might be the average brightness of the picture (the mean of all pixel values), that numerically stands between `0` and `255`.

Automatically exposed pictures tend to have average values near `128`. My wish is to take that into account, and, if my average value is, say, `150`, add, say, `1` to the EV because the scene is presumably brighter.

Does this, approximately speaking, make any sense? Is there a relation between a single stop and the consequent variation in the average picture brightness?

Note: of course this logic breaks if the picture is very underexposed (has some 0s) or very overexposed (has 255s) because then you can't use the average brightness information. Let's say all pictures have average brightness between 80 and 200.

• "even with a large approximation" the Lux value of every picture is 5. Seriously, even if the approximation can be very large, you should still give an estimate of some kind of threshold.
– null
May 19 '16 at 20:26
• @null to break down my issue, let's say I have a sequence of pictures looking at the same scene, and I want to infer the luminance conditions (e.g. which of these pictures was taken in brightest conditions?). I searched here, and as expected you do take brightness measurements seriously, so I spoke about approximation. With links provided in one of the answers, I think I can get a pretty good indicator of the brightness, but not if my pictures are not well exposed, in which case the equations (AFAIU) don't apply. May 19 '16 at 20:39
• Possible duplicate of How to calculate Lux from EV? May 19 '16 at 21:16
• I'm voting to close this question as too broad, which just barely beat out off-topic. I don't mean to be glib about it, but this is fundamentally an image processing conversation.
– scottbb
May 20 '16 at 2:43
• It's basically another case of wanting to use a camera as an instrument for something other than photography. This is like hammering in nails with a screwdriver (or screws with a hammer) — you might be able to make it work, but you probably are better off just using the right tool in the first place. May 20 '16 at 3:01

The good part is that the camera does measure brightness of the seen in terms of an EV value.

There are several different ways to do the measurement. Most of the modes calculate the result from a weighted average of the image. Some put more emphasis in the middle part (spot metering for example). If you know what mode was used and how the weights are distributed for that mode you know what pixel values contributed to the settings and thus the EV value.

The issue with that is that you do not know the distribution of weights over the image. This is proprietary information of the camera manufacturer. You could reverse engineer this information with a lot of testing, but that would be very time consuming and the results may only apply to the tested camera.

On top of that, there's no guarantee that the image taken has anything to do with a meter reading whatsoever. The measurement could be taken from subject matter that's not even part of the image. Or as you stated: the settings could be chosen manually. You could consider them arbitrary or random. This is why one could say that there's no "correct" exposure. Photography is an art after all. You could work yourself around that by taking the images under controlled circumstances so that you know that the settings used are based on a measurement of the actual subject matter.

On the other hand, settings for exposure compensation (that is, to deliberately move settings away from what was metered) are usually limited to plus minus 2 EV (3 on some models) This value indicates that the desirable exposure settings are usually in that range from the metered settings. Depending on what kind of approximation you are looking for, you could say that the used settings are the same as the metered settings with a maximum error of said plus minus 2 EV.

Dynamic range is limited and values clip. If the white clipping happens at value 255 depends on the bit depth of the data that the sensor produces. A lot of cameras produce more than 8 bit per channel. If you have an image that includes the sun or a reflection of it, those regions are usually blown out. The logic falls apart as you say. Finding a reasonable threshold for how many pixels are allowed to be blown out in an image to still apply the logic to it sounds like a tough statistical task.

And then there is flash. I take quite a few images with the meter of the camera blinking to signal underexposure. But that's not relevant to me in those situations, because I use a flash that compensates the darkness of the ambient light. The logic falls even more apart in this scenario.

## conclusion

I don't think this makes sense in general, because there are too many things the influence the result, which makes the result itself somewhat arbitrary.

In a controlled environment, this could make sense though. Say for example an led in a box is photographed and the lux can be estimated from the photograph. A calibration with a lux meter would be helpful.

So much for the theory. The "correct" exposure that the metering modes are aiming for are an empirical value. It's what turned out to work for the average image. My suggestions would be to do the same. Take a few series of images along with a proper measurement from a lux meter of the scene. Then see if there's any correlation between the values.

• This answer actually satisfies me the most. My images are somehow controlled (no flash, always outdoor, hopefully no sun involved). I think I'm going down your way, more or less: take hundreds of photos and look for a relation between stops of under/overexposure and distance of the average pixel value from 128. Then with stops I can just move down/up the rows of that chart. Thank you all guys! May 20 '16 at 9:12

The main part of this question comes down to How to calculate Lux from EV?, leaving only the problem of estimating the overexposure or underexposure.

It seems that you want to do at automatically. That's easy to answer: you can't, really, unless all of your images are of similar, known subjects. Otherwise, you would need a great deal of artificial intelligence to follow scene recognition. That's because there's no way to tell the difference between overexposure and a polar bear and a snowstorm, or underexposure and a black horse in a coal mine.

You say:

Automatically exposed pictures tend to have average values near 128.

And this is the crux of the problem. It is likely that many underexposed and overexposed pictures will also have this middle value. That's because while modern cameras attempt rudimentary scene understanding with matrix metering modes, they're often just guessing — and, here's the thing: it's when that guess is wrong that you're most likely to see underexposed or overexposed images. So, you can't just replicate that incorrect guess; that won't get you anywhere.

Does this, approximately speaking, make any sense? Is there a relation between a single stop and the consequent variation in the average picture brightness?

There is a relation, although the exact one will depend on your processing settings — but it's only a relation when you're starting from a known place. And if you had that, you wouldn't have this question in the first place.

• You are right, I will underestimate brightness when there are black horses around, and overestimate when there are reflective objects. I didn't think about it. "There is a relation but it's only a relation when you are starting from a known place" what do you mean? May 20 '16 at 9:00

You can't get any light information from the jpeg, the mapping is highly non trivial and depends on the RAW processing algorithm. No two pictures will use the same curve.

You could get light information from the RAW file, however. However you need the actual recorded values, you can't pass the file through a RAW processor, you need to parse the RAW file itself.

• You mean the mapping from scene brightness to pixel values? May 19 '16 at 20:42
• I mean the mapping from RAW values to pixel values. The mapping from scene brightness to RAW values is more or less linear (if it fits in the dynamic range, etc), and depends on exposure in the obvious way, but the mapping between RAW values and pixel values is highly scene and algorithm dependent. May 19 '16 at 20:47
• .. got to read something about RAW, I guess. Let me think about it for a while, thank you very much. May 19 '16 at 20:56