blob: fb4e9643df1b3c8bca731d69b64cba12524473d2 [file] [log] [blame]
Yin-Chia Yeh00d504d2018-03-15 11:08:49 -07001#!/bin/ipython
2
3import argparse
4import numpy as np
5import matplotlib.pyplot as plt
6import sys
7
8## general defines
9
10linecolor = "#%x%x%x" % ( 217, 234, 211 )
11markercolor = "#%x%x%x" % ( 217/2, 234/2, 211/2 )
12
13# Draw pretty plot
14def doc_plot(fig, x, y):
15
16 plt.figure(fig.number)
17 fig.clear()
18
19 lines, = plt.plot(x,y)
20 lines.set_color(linecolor)
21 lines.set_linewidth(4)
22 lines.set_marker('o')
23 lines.set_markeredgecolor(markercolor)
24 lines.set_markersize(6)
25 lines.set_markeredgewidth(2)
26
27 axes = fig.get_axes()[0]
28 axes.set_aspect(1)
29 axes.set_ybound(0,1)
30 axes.set_xbound(0,1)
31 axes.grid(True)
32 axes.xaxis.label.set_text(r'$P_{IN}$')
33 axes.xaxis.label.set_fontsize(14)
34 axes.yaxis.label.set_text(r'$P_{OUT}$')
35 axes.yaxis.label.set_fontsize(14)
36
37# Print out interleaved coefficients for HAL3 tonemap curve tags
38def doc_coeff(x,y):
39 coeffs = np.vstack((x, y)).reshape(-1,order='F')
40 coeff_str = "[ "
41 for val in coeffs[:-1]:
42 coeff_str += "%0.4f, " % val
43
44 coeff_str += "%0.4f ]" % coeffs[-1]
45
46 print coeff_str
47
48def doc_map(fig, imgMap, index):
49 plt.figure(fig.number)
50 fig.clear()
51 plt.imshow(imgMap - 1, interpolation='nearest')
52 for x in range(0, np.size(imgMap, 1)):
53 for y in range(0, np.size(imgMap, 0)):
54 plt.text(x,y, imgMap[y,x,index], color='white')
55
56 axes = fig.get_axes()[0]
57 axes.set_xticks(range(0, np.size(imgMap, 1)))
58 axes.set_yticks(range(0, np.size(imgMap, 0)))
59
60## Check arguments
61
62parser = argparse.ArgumentParser(description='Draw plots for camera HAL3.x implementation spec doc')
63parser.add_argument('--save_figures', default=False, action='store_true',
64 help='Save figures as pngs')
65
66args = parser.parse_args()
67
68## Linear mapping
69
70x_lin = np.linspace(0,1,2)
71y_lin = x_lin
72
73lin_fig = plt.figure(1)
74doc_plot(lin_fig, x_lin, y_lin)
75
76lin_title = 'Linear tonemapping curve'
77plt.title(lin_title)
78print lin_title
79doc_coeff(x_lin, y_lin)
80
81if args.save_figures:
82 plt.savefig('linear_tonemap.png',bbox_inches='tight')
83
84## Inverse mapping
85
86x_inv = x_lin
87y_inv = 1 - x_lin
88
89inv_fig = plt.figure(2)
90doc_plot(inv_fig, x_inv, y_inv)
91
92inv_title = 'Inverting tonemapping curve'
93plt.title(inv_title)
94print inv_title
95doc_coeff(x_inv, y_inv)
96
97if args.save_figures:
98 plt.savefig('inverse_tonemap.png',bbox_inches='tight')
99
100## Gamma 1/2.2
101
102x_gamma = np.linspace(0, 1, 16);
103
104y_gamma = x_gamma**(1/2.2)
105
106gamma_fig = plt.figure(3)
107doc_plot(gamma_fig, x_gamma, y_gamma)
108
109gamma_title = r'$\gamma=1/2.2$ tonemapping curve'
110plt.title(gamma_title)
111print gamma_title
112doc_coeff(x_gamma, y_gamma)
113
114if args.save_figures:
115 plt.savefig('gamma_tonemap.png',bbox_inches='tight')
116
117## sRGB curve
118
119x_srgb = x_gamma
120y_srgb = np.where(x_srgb <= 0.0031308, x_srgb * 12.92, 1.055*x_srgb**(1/2.4)-0.055)
121
122srgb_fig = plt.figure(4)
123doc_plot(srgb_fig, x_srgb, y_srgb)
124
125srgb_title = 'sRGB tonemapping curve'
126plt.title(srgb_title)
127print srgb_title
128doc_coeff(x_srgb, y_srgb)
129
130if args.save_figures:
131 plt.savefig('srgb_tonemap.png',bbox_inches='tight')
132
133## Sample lens shading map
134
135shadingMapSize = np.array([3, 4])
136shadingMap1 = np.array(
137 [ 1.3, 1.2, 1.15, 1.2, 1.2, 1.2, 1.15, 1.2, 1.1, 1.2, 1.2, 1.2, 1.3, 1.2, 1.3, 1.3,
138 1.2, 1.2, 1.25, 1.1, 1.1, 1.1, 1.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.2, 1.3, 1.25, 1.2,
139 1.3, 1.2, 1.2, 1.3, 1.2, 1.15, 1.1, 1.2, 1.2, 1.1, 1.0, 1.2, 1.3, 1.15, 1.2, 1.3 ])
140redMap = shadingMap1[0::4].reshape(shadingMapSize)
141greenEMap = shadingMap1[1::4].reshape(shadingMapSize)
142greenOMap = shadingMap1[2::4].reshape(shadingMapSize)
143blueMap = shadingMap1[3::4].reshape(shadingMapSize)
144
145rgbMap = np.dstack( (redMap, (greenEMap + greenOMap) / 2, blueMap) )
146redMap = np.dstack( (redMap, np.zeros(shadingMapSize), np.zeros(shadingMapSize) ) )
147greenEMap = np.dstack( (np.zeros(shadingMapSize), greenEMap, np.zeros(shadingMapSize) ) )
148greenOMap = np.dstack( (np.zeros(shadingMapSize), greenOMap, np.zeros(shadingMapSize) ) )
149blueMap = np.dstack( (np.zeros(shadingMapSize), np.zeros(shadingMapSize), blueMap ) )
150
151redImg = plt.figure(5)
152doc_map(redImg, redMap, 0)
153plt.title('Red lens shading map')
154
155if args.save_figures:
156 plt.savefig('red_shading.png',bbox_inches='tight')
157
158greenEImg = plt.figure(6)
159doc_map(greenEImg, greenEMap, 1)
160plt.title('Green (even rows) lens shading map')
161
162if args.save_figures:
163 plt.savefig('green_e_shading.png',bbox_inches='tight')
164
165greenOImg = plt.figure(7)
166doc_map(greenOImg, greenOMap, 1)
167plt.title('Green (odd rows) lens shading map')
168
169if args.save_figures:
170 plt.savefig('green_o_shading.png',bbox_inches='tight')
171
172blueImg = plt.figure(8)
173doc_map(blueImg, blueMap, 2)
174plt.title('Blue lens shading map')
175
176if args.save_figures:
177 plt.savefig('blue_shading.png',bbox_inches='tight')
178
179rgbImg = plt.figure(9)
180
181rgbImg.clear()
182plt.imshow(1/rgbMap,interpolation='bicubic')
183
184axes = rgbImg.get_axes()[0]
185axes.set_xticks(range(0, np.size(rgbMap, 1)))
186axes.set_yticks(range(0, np.size(rgbMap, 0)))
187
188plt.title('Image of uniform white wall (inverse shading map)')
189
190if args.save_figures:
191 plt.savefig('inv_shading.png',bbox_inches='tight')
192
193# Rec. 709
194x_rec709 = x_gamma
195y_rec709 = np.where(x_rec709 <= 0.018, x_rec709 * 4.500, 1.099*x_rec709**0.45-0.099)
196
197rec709_fig = plt.figure(10)
198doc_plot(rec709_fig, x_rec709, y_rec709)
199
200rec709_title = 'Rec. 709 tonemapping curve'
201plt.title(rec709_title)
202print rec709_title
203doc_coeff(x_rec709, y_rec709)
204
205if args.save_figures:
206 plt.savefig('rec709_tonemap.png',bbox_inches='tight')
207
208
209# Show figures
210
211plt.show()