-
Notifications
You must be signed in to change notification settings - Fork 0
/
algorithm.py
57 lines (50 loc) · 2.05 KB
/
algorithm.py
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
57
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
def readImagesAndTimes(paths):
image = []
for x in paths:
image.append(cv.imread(x))
align = cv.createAlignMTB()
align.process(image, image)
return image
def tone_merge(images, times):
merge = cv.createMergeDebevec()
hdr = merge.process(images, times=times.copy())
return hdr
def tone_map(HDR_object):
tonemap = cv.createTonemap(gamma=2.2)
result = tonemap.process(HDR_object.copy())
return result
def save_result(HDR_result):
result_image = np.clip(HDR_result * 255, 0, 255).astype('uint8')
cv.imwrite("./Test Images/5/Inconsistent/Result.jpg", result_image)
def graph_camera_response_function(images, times):
calibration = cv.createCalibrateDebevec()
crf_debevec = calibration.process(images, times=times)
return crf_debevec
if __name__ == "__main__":
time = np.array([1.0/8000.0, 1.0/1020.0, 1.0/100.0, 1.0/20.0], dtype=np.float32)
paths = ["./Test Images/2/Inconsistent/1.jpg",
"./Test Images/2/Inconsistent/2.jpg",
"./Test Images/2/Inconsistent/3.jpg",
"./Test Images/2/Inconsistent/4.jpg"]
images = readImagesAndTimes(paths)
merge_mertens = cv.createMergeMertens()
fusion = merge_mertens.process(images)
fusion_8bit = np.clip(fusion * 255, 0, 255).astype('uint8')
cv.imwrite("./Test Images/2/Inconsistent/fusion_result.png", fusion_8bit)
hdr_merge = tone_merge(images, time)
mapping = tone_map(hdr_merge)
save_result(mapping)
x_value = [x for x in range(0, 256)]
vectors = graph_camera_response_function(images, time)
plt.plot(x_value, vectors[:, :, 0], label='B', color='b')
plt.plot(x_value, vectors[:, :, 1], label='G', color='g')
plt.plot(x_value, vectors[:, :, 2], label='R', color='r')
plt.xlabel("pixel value intensity")
plt.ylabel("Calibrated intensity")
plt.legend()
plt.title("Estimated camera response function for Inconsistent white balance")
plt.savefig('./Test Images/2/Inconsistent/CRF.png')
plt.show()