Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine difference in stops between images with no EXIF data

I have a set of images of the same scene but shot with different exposures. These images have no EXIF data so there is no way to extract useful info like f-stop, shutter speed etc.

What I'm trying to do is to determine the difference in stops between the images i.e. Image1 is +1.3 stops of Image0.

My current approach is to first calculate luminance from the image's RGB values using the equation

L = 0.2126 * R + 0.7152 * G + 0.0722 * B

I've seen different numbers being used in the equation but generally it should not affect the end result L too much.

After that I derive the log-average luminance of the image.

exp(avg of log(luminance of image))

But somehow the log-avg luminance doesn't seem to give much indication on exposure difference btw the images. Any ideas on how to determine exposure difference?

edit: on c/c++

like image 811
cks2k2 Avatar asked Dec 14 '25 20:12

cks2k2


1 Answers

You have to generally solve two problems:

1. Linearize your image data

(In case it's not obvious what is meant: two times more light collected by your pixel shall result in two times the intensity value in your linearized image.)

Your image input might be (sufficiently) linearized already -> you may skip to part 2. If your content came from a camera and it's a JPEG, then this will most certainly not be the case.

The real 'solution' to this problem is finding the camera response function, which you want to invert and apply to your image data to get linear intensity values. This is by no means a trivial task. The EMoR model is widely used in all sorts of software (Photoshop, PTGui, Photomatix, etc.) to describe camera response functions. Some open source software solving this problem (but using a different model iirc) is PFScalibrate.

Having that said, you may get away with a simple inverse gamma application. A rough 'gestimation' for the right gamma value might be found by doing this:

  1. capture an evenly lit, static scene with two exposure times e and e/2
  2. apply a couple of inverse gamma transforms (e.g. for 1.8 to 2.4 in 0.1 steps) on both images
  3. multiply all the short exposure images with 2.0 and subtract them from the respective long exposure images
  4. pick the gamma that lead to the smallest overall difference

2. Find the actual difference of irradiation in stops, i.e. log2(scale factor)

Presuming the scene was static (no moving objects or camera), this is relatively easy:

sum1 = sum2 = 0
foreach pixel pair (p1,p2) from the two images:
  if p1 or p2 is close to 0 or 255:
    skip this pair
  sum1 += p1 and sum2 += p2
return log2(sum1 / sum2)

On large images this will certainly work just as well and a lot faster if you sub-sample the images.

If the camera was static but the scene was not (moving objects), this starts to work less well. I produced acceptable results in this case by simply repeating the above procedure several times and use the output of the previous run as an estimate for the correct scale factor and then discard pixel pairs who's quotient is too far away from the current estimate. So basically replacing the above if line with the following:

if <see above> or if abs(log2(p1/p2) - estimate) > 0.5:

I'd stop the repetition after a fixed number of iterations or if two consecutive estimates are sufficiently close to each other.

EDIT: A note about conversion to luminance

You don't need to do that at all (as Tony D mentioned already) and if you insist, then do it after the linearization step (as Mark Ransom noted). In a perfect setting (static scene, no noise, no de-mosaicing, no quantization) every channel of every pixel would have the same ratio p1/p2 (if neither is saturated). Therefore the relative weighting of the different channels is irrelevant. You may sum over all pixels/channels (weighing R, G and B equally) or maybe only use the green channel.

like image 163
axxel Avatar answered Dec 17 '25 12:12

axxel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!