-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (40 loc) · 1.71 KB
/
main.py
File metadata and controls
56 lines (40 loc) · 1.71 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import glob
import cv2
import argparse
import numpy as np
from utils import *
def main(config):
list_file, exps = load(config.test_path)
stack = read(list_file)
num_channels = stack.shape[-1]
hdr_img = np.zeros(stack[0].shape, dtype=np.float64)
for c in range(num_channels):
layer_stack = [img[:,:,c] for img in stack]
sample = sample_intensity(layer_stack)
curve = estimate_curve(sample, exps, 100.)
img_rad = computeRadiance(np.array(layer_stack), exps, curve)
hdr_img[:,:, c] = cv2.normalize(img_rad, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX)
if config.tonemap =='gamma':
output = np.uint8(globalTonemap(hdr_img, 1.3) * 255.)
else:
tm = cv2.createTonemapMantiuk()
output = np.uint8(255. * tm.process((hdr_img/255.).astype(np.float32)))
if config.cmap:
from matplotlib.pylab import cm
colorize = cm.jet
cmap = np.float32(cv2.cvtColor(np.uint8(hdr_img), cv2.COLOR_BGR2GRAY)/255.)
cmap = colorize(cmap)
cv2.imwrite(os.path.join(config.test_path, 'cmap.jpg'), np.uint8(cmap*255.))
template = stack[len(stack)//2]
image_tuned = intensityAdjustment(output, template)
output = cv2.normalize(output, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX)
return output.astype(np.uint8)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--test_path', type=str, default="imgs/night01/")
parser.add_argument('--tonemap', type=str, default=' ')
parser.add_argument('--cmap', type=bool, default=False)
config = parser.parse_args()
out = main(config)
cv2.imwrite(os.path.join(config.test_path, 'hdr.jpg'), out)