image-processingopenexr

Splitting OpenEXR into different exposure images


I'm trying to use this dataset to do Exposure Meging (Fusion) in Python. Each image in the dataset has an OpenEXR file that can be downloaded (i don't have much experience with this file format).

I want to extract different samples (jpg or png) from the OpenEXR file with different exposures .

I managed to do that in Darktable :

The problem : I have 100 images and i want to automate this process. any idea on how to do that ?

Thank you in advance


Solution

  • Since each increment of EV ("Exposure Value") corresponds to doubling the exposure, and EXR files are in linear light (not gamma-encoded), you would expect that you can double the pixel values in an EXR file to add 1EV and halve them to do -1EV...

    So, I downloaded the Luxo EXR file from here. Then I went into Photoshop and clicked:

    Image -> Mode -> 8-bits/channel
    

    and selected Method = Exposure and Gamma and set exposure=+1 and saved the resulting file as a JPEG with +1 in its name. I repeated that for EV-3, EV-2, EV+0, EV+1, EV+2, EV+3.

    enter image description here

    I then looked at the resulting files with ImageMagick using commands like the following in the Terminal to examine the mean value of the combined RGB image:

    magick identify -verbose image-EV+2.jpg
    

    I then went about producing those same mean values, and found that the following works:

    # To increase 1 EV
    magick input.exr -evaluate multiply 2 result.jpg
    
    # To increase 2 EV
    magick input.exr -evaluate multiply 4 result.jpg
    
    # To increase 3 EV
    magick input.exr -evaluate multiply 8 result.jpg
    

    And so on...


    So, I wrote a bash script to do that as follows, which you could save in your HOME directory as adjust.sh:

    #!/bin/bash
    
    # Default file, if none specified
    file=${1:-/Users/mark/Desktop/LuxoDoubleChecker.exr}
    
    # Default EV of +1, if none specified
    EV=${2:-1}
    
    # Strip extension
    base="${file%.*}"
    
    # Apply given EV to file and save with new name
    new="${base}EV${EV}.jpg"
    echo "Applying EV $EV to $file, saving as $new"
    magick "$file" -evaluate multiply $(bc -l <<< "2^$EV") "$new"
    

    Then, just necessary once, make it executable:

    chmod +x $HOME/adjust.sh
    

    And then you run it like this to add +3EV to SomeImage.exr:

    ~/adjust.sh SomeImage.exr 3
    

    Sample Output

    Applying EV 3 to SomeImage.exr, saving as SomeImageEV3.jpg
    

    Alternatively, if you save this script as allEVs.sh, it will load the specified image just once and generate all 7 exposures in one go without re-reading the input EXR file 7 times:

    #!/bin/bash
    
    # Default file, if none specified
    file=${1:-/Users/mark/Desktop/LuxoDoubleChecker.exr}
    
    # Strip extension to get base without extension
    base="${file%.*}"
    
    magick "$file" \
        \( +clone -evaluate multiply 0.125 -write "${base}EV-3.jpg" +delete \)  \
        \( +clone -evaluate multiply 0.25  -write "${base}EV-2.jpg" +delete \)  \
        \( +clone -evaluate multiply 0.5   -write "${base}EV-1.jpg" +delete \)  \
        \( +clone -evaluate multiply 1     -write "${base}EV-0.jpg" +delete \)  \
        \( +clone -evaluate multiply 2     -write "${base}EV+1.jpg" +delete \)  \
        \( +clone -evaluate multiply 4     -write "${base}EV+2.jpg" +delete \)  \
                  -evaluate multiply 8     "${base}EV+3.jpg"
    

    enter image description here

    Please check carefully that this works correctly for you before basing a lifetime's analysis on it...

    Keywords: Image processing, HDR, High Dynamic Range, EXR, EV, Exposure Value, f-stop, stop, stops, exposure, increase, decrease, tone map, ImageMagick.