GithubHelp home page GithubHelp logo

ssarcandy / hdr-imaging Goto Github PK

View Code? Open in Web Editor NEW
81.0 8.0 15.0 64.83 MB

An implementation of "Paul E. Debevec, Jitendra Malik, Recovering High Dynamic Range Radiance Maps from Photographs, SIGGRAPH 1997."

Home Page: https://ssarcandy.tw/2017/04/16/High-Dynamic-Range-Imaging/

Python 2.61% Jupyter Notebook 96.84% Batchfile 0.54%
ipython-notebook image-processing hdr-image python3 opencv3

hdr-imaging's Introduction

HDR imaging

Requirement

  • python3 (or higher)
  • opencv 3.0 (or higher)

You will need to install some package using pip3:

  • numpy
  • matplotlib

Usage

$ python HDR-playground.py <input img dir> <output .hdr name>

# for example
$ python ./HDR-playground.py taipei taipei.hdr

I also provide an jupyter version(HDR-playground.ipynb), it’s function is same as HDR-playground.py. jupyter is really convenient for develop python program!

Input format

The input dir should have:

  • Some .png images
  • A image_list.txt, file should contain:
    • filename
    • exposure
    • 1/shutter_speed

This is an example for image_list.txt:

# Filename   exposure 1/shutter_speed
DSC_0058.png 32        0.03125
DSC_0059.png 16        0.0625
DSC_0060.png  8        0.125
DSC_0061.png  4        0.25
DSC_0062.png  2        0.5
DSC_0063.png  1        1
DSC_0064.png  0.5      2
DSC_0065.png  0.25     4
DSC_0066.png  0.125    8
DSC_0067.png  0.0625  16

Output

The program will output:

  • A .hdr image
  • A reconstruct RGB response curve plot
  • A pseudo-color radiance map(with log value)

for sample output, you can see HDR-playground.ipynb as reference.

Tonemap

I use tmo for tonemapping, it implement 24 algorithms.
I write a script tonemap.bat for auto-run all 24 algorithms.

$ tonemap.bat <filename without extension>

Make sure all tm_*.exe is in your system PATH

Environment

I test my code in Window10, but it should work fine in macOS/Linux(exclude tonemapping reference program need run in Windows)

hdr-imaging's People

Contributors

ssarcandy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hdr-imaging's Issues

Problems on Pixel Sampling

Is there a bug in Z[img_index, ij] = pixel ? Since there will be several cases where different combination of i and j leads to same position of ij.

Small artifacts in HDR Image

In the resuting .hdr image are cyan or magenta colored pixels. Are there parameters wrong or is there an issue with the calculations? I tried diffrent hdr viewer and tonemapper, all witrh the same result.

artifacts

Downsampling of images in hdr_debvec( ) is not as good as sampling individual pixels from them

Greetings!

Thanks for this implementation, I find that it successfully achieved what the OpenCV version currently does not, specifically with respect to proper weighting of saturated pixels.

To support, after some research, I have found an improvement.

Basically, for the current hdr_debvec( ) function, I kept on getting nasty response functions like this:
response-curve_1

I realized that what is technically happening is downsampling of the pixel values, such that the pixels are averaged / interpolated across each other. This is very problematic in the case where the user has many, many saturated pixels: averaging these values will make them unsaturated, and create a false color in between.

I figured a more robust approach would be to instead just uniformly sample individual pixels across a grid of the image.

Here is how that changed my camera response function (3600 samples):
response_curve_3600samples

Here is the new implementation (not my best code but it works):

def hdr_debvec(img_list, exposure_times, number_of_samples_per_dimension=60):
    B = [math.log(e,2) for e in exposure_times]
    l = constant.L
    w = [z if z <= 0.5*255 else 255-z for z in range(256)]

    samples = []
    width = img_list[0].shape[0]
    height = img_list[0].shape[1]
    width_iteration = width / number_of_samples_per_dimension
    height_iteration = height / number_of_samples_per_dimension

    w_iter = 0
    h_iter = 0

    Z = np.zeros((len(img_list), number_of_samples_per_dimension*number_of_samples_per_dimension))
    for img_index, img in enumerate(img_list):
        h_iter = 0
        for i in range(number_of_samples_per_dimension):
            w_iter = 0
            for j in range(number_of_samples_per_dimension):
                if math.floor(w_iter) < width and math.floor(h_iter) < height:
                    pixel = img[math.floor(w_iter), math.floor(h_iter)]
                    Z[img_index, i*j] = pixel
                w_iter += width_iteration
            h_iter += height_iteration
    
    return response_curve_solver(Z, B, l, w)

Thanks again and great work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.