HDR fusion (Mertens) gives different results in Python Vs. C++

asked 2015-12-06 04:21:06 -0600

ej gravatar image

updated 2015-12-06 04:21:46 -0600

When I run the HDR Mertens exposure fusion in Python I get weird colors artifact, that I don't get when I run the exact same function in c++. (I just run the HDR Tutorial)

Seems to me like some problem with the data types, but I tried every option and nothing works. Am I doing something wrong?

I'm running Python 3.5 64-bit with OpenCV 3.0.0.

The exposures images were taken from Wikipedia: 1/30 sec, 1/4 sec, 2.5 sec, 15 sec.

The Python code:

import cv2
import numpy as np

img_fn = ["640px-StLouisArchMultExpEV+4.09.jpg",
img_list = [cv2.imread(fn) for fn in img_fn]

# Exposure fusion using Mertens
mergeMertens = cv2.createMergeMertens()
resFusion = mergeMertens.process(img_list)

# Convert datatype to 8-bit and save
resFusion_8bit = np.uint8(resFusion*255)
cv2.imwrite("fusion.png", resFusion_8bit)

The result I get in Python:

image description

The result I get in C++:

image description

edit retag flag offensive close merge delete


hmm, you seem to be overflowing somehow.

can you try some kind of [0..1] normalization before converting to CV8U ?

berak gravatar imageberak ( 2015-12-06 09:35:59 -0600 )edit

Yes, the problem was indeed overflow. The result of the fusion have values lower the 0 and larger then 1 (bug?) If I clip them before converting to CV8U the problem disappear.

ej gravatar imageej ( 2015-12-07 13:32:19 -0600 )edit