HDR fusion (Mertens) gives different results in Python Vs. C++
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",
"640px-StLouisArchMultExpEV+1.51.jpg",
"640px-StLouisArchMultExpEV-1.82.jpg",
"640px-StLouisArchMultExpEV-4.72.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:
The result I get in C++:
hmm, you seem to be overflowing somehow.
can you try some kind of [0..1] normalization before converting to CV8U ?
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.