-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTonemapReinhard_npy.py
More file actions
27 lines (24 loc) · 932 Bytes
/
Copy pathTonemapReinhard_npy.py
File metadata and controls
27 lines (24 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# tonemap all .npy images in current dir to .jpg using OpenCV Reinhard method
import os
import cv2
import numpy as np
for f in os.listdir(os.getcwd()):
if f.endswith('.npy'):
hdr = np.load(f)
hdr = hdr.astype('float32')
hdr = (hdr - np.min(hdr)) / (np.max(hdr) - np.min(hdr))
grayscale = True
if hdr.ndim == 3:
if hdr.shape[2] == 3:
# RGB image (H, W, 3)
hdr = cv2.cvtColor(hdr, cv2.COLOR_RGB2BGR)
grayscale = False
elif hdr.shape[2] == 1:
# grayscale image (H, W, 1)
hdr = hdr[:, :, 0]
if grayscale:
hdr = np.stack([hdr, hdr, hdr], axis=2)
tmo = cv2.createTonemapReinhard(intensity=-1.0, light_adapt=0.8, color_adapt=0.0)
tonemapped = tmo.process(hdr)
f_ = f.split('.')[0] + '.jpg'
cv2.imwrite(f_, tonemapped * 255)