gabrieleilertsen / hdrcnn

HDR image reconstruction from a single exposure using deep CNNs
https://computergraphics.on.liu.se/hdrcnn/
BSD 3-Clause "New" or "Revised" License
514 stars 101 forks source link

cv2.randn takes in an array of mean and standard-deviations #4

Closed GreenSlime96 closed 6 years ago

GreenSlime96 commented 6 years ago

https://github.com/gabrieleilertsen/hdrcnn/blob/bedb6c59b6229259d432def865bcc0ab55f89d8e/training_code/virtualcamera/virtualcamera.cpp#L279

Hi Gabriel,

I notice that your virtual camera uses the OpenCV randn function. In a Python port of the camera I notice that noise is only added in one channel due to the nature of the function. I believe this is unintentional and that you mean to add noise equally (or not) across all channels, instead of only to the first channel.

See: http://answers.opencv.org/question/79758/how-to-add-gaussian-noise-in-all-channels-of-an-image-with-randn/

gabrieleilertsen commented 6 years ago

Hi! And thank you for pointing that out. I have not experienced this problem, and to be sure I also tested the noise code. The result with large amounts of noise (std = 1) looks like this:

noise

So I assume the behavior can depend on your particular installation of OpenCV. In order to make the code more general I have updated to use vectors instead of scalars in the randn function. I hope you will get the expected behavior now. And thank you for helping in making the code generalize better :)

GreenSlime96 commented 6 years ago

Thanks for looking into this, Gabriel. Additionally it seems that adding noise to the image (line 280) where there are already 0 values can cause your assertion to fail, as occasionally the square-rooting function in line 285 returns a NaN.

I fixed this issue by changing line 280 as follows:

host_roi = max(0, host_roi + noise);

Do share with me your thoughts.

gabrieleilertsen commented 6 years ago

Absolutely, that makes sense. Negative values should not be allowed. I've updated according to your suggestion. Thanks!