summaryrefslogtreecommitdiffstats
path: root/camera/docs/plots.py
blob: fb4e9643df1b3c8bca731d69b64cba12524473d2 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/ipython

import argparse
import numpy as np
import matplotlib.pyplot as plt
import sys

## general defines

linecolor = "#%x%x%x" % ( 217, 234, 211 )
markercolor = "#%x%x%x" % ( 217/2, 234/2, 211/2 )

# Draw pretty plot
def doc_plot(fig, x, y):

  plt.figure(fig.number)
  fig.clear()

  lines, = plt.plot(x,y)
  lines.set_color(linecolor)
  lines.set_linewidth(4)
  lines.set_marker('o')
  lines.set_markeredgecolor(markercolor)
  lines.set_markersize(6)
  lines.set_markeredgewidth(2)

  axes = fig.get_axes()[0]
  axes.set_aspect(1)
  axes.set_ybound(0,1)
  axes.set_xbound(0,1)
  axes.grid(True)
  axes.xaxis.label.set_text(r'$P_{IN}$')
  axes.xaxis.label.set_fontsize(14)
  axes.yaxis.label.set_text(r'$P_{OUT}$')
  axes.yaxis.label.set_fontsize(14)

# Print out interleaved coefficients for HAL3 tonemap curve tags
def doc_coeff(x,y):
  coeffs = np.vstack((x, y)).reshape(-1,order='F')
  coeff_str = "[ "
  for val in coeffs[:-1]:
    coeff_str += "%0.4f, " % val

  coeff_str += "%0.4f ]" % coeffs[-1]

  print coeff_str

def doc_map(fig, imgMap, index):
  plt.figure(fig.number)
  fig.clear()
  plt.imshow(imgMap - 1, interpolation='nearest')
  for x in range(0, np.size(imgMap, 1)):
    for y in range(0, np.size(imgMap, 0)):
      plt.text(x,y, imgMap[y,x,index], color='white')

  axes = fig.get_axes()[0]
  axes.set_xticks(range(0, np.size(imgMap, 1)))
  axes.set_yticks(range(0, np.size(imgMap, 0)))

## Check arguments

parser = argparse.ArgumentParser(description='Draw plots for camera HAL3.x implementation spec doc')
parser.add_argument('--save_figures', default=False, action='store_true',
                   help='Save figures as pngs')

args = parser.parse_args()

## Linear mapping

x_lin = np.linspace(0,1,2)
y_lin = x_lin

lin_fig = plt.figure(1)
doc_plot(lin_fig, x_lin, y_lin)

lin_title = 'Linear tonemapping curve'
plt.title(lin_title)
print lin_title
doc_coeff(x_lin, y_lin)

if args.save_figures:
  plt.savefig('linear_tonemap.png',bbox_inches='tight')

## Inverse mapping

x_inv = x_lin
y_inv = 1 - x_lin

inv_fig = plt.figure(2)
doc_plot(inv_fig, x_inv, y_inv)

inv_title = 'Inverting tonemapping curve'
plt.title(inv_title)
print inv_title
doc_coeff(x_inv, y_inv)

if args.save_figures:
  plt.savefig('inverse_tonemap.png',bbox_inches='tight')

## Gamma 1/2.2

x_gamma = np.linspace(0, 1, 16);

y_gamma = x_gamma**(1/2.2)

gamma_fig = plt.figure(3)
doc_plot(gamma_fig, x_gamma, y_gamma)

gamma_title = r'$\gamma=1/2.2$ tonemapping curve'
plt.title(gamma_title)
print gamma_title
doc_coeff(x_gamma, y_gamma)

if args.save_figures:
  plt.savefig('gamma_tonemap.png',bbox_inches='tight')

## sRGB curve

x_srgb = x_gamma
y_srgb = np.where(x_srgb <= 0.0031308, x_srgb * 12.92, 1.055*x_srgb**(1/2.4)-0.055)

srgb_fig = plt.figure(4)
doc_plot(srgb_fig, x_srgb, y_srgb)

srgb_title = 'sRGB tonemapping curve'
plt.title(srgb_title)
print srgb_title
doc_coeff(x_srgb, y_srgb)

if args.save_figures:
  plt.savefig('srgb_tonemap.png',bbox_inches='tight')

## Sample lens shading map

shadingMapSize = np.array([3, 4])
shadingMap1 = np.array(
    [ 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,
      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,
      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 ])
redMap = shadingMap1[0::4].reshape(shadingMapSize)
greenEMap = shadingMap1[1::4].reshape(shadingMapSize)
greenOMap = shadingMap1[2::4].reshape(shadingMapSize)
blueMap = shadingMap1[3::4].reshape(shadingMapSize)

rgbMap = np.dstack( (redMap, (greenEMap + greenOMap) / 2, blueMap) )
redMap = np.dstack( (redMap, np.zeros(shadingMapSize), np.zeros(shadingMapSize) ) )
greenEMap = np.dstack( (np.zeros(shadingMapSize), greenEMap, np.zeros(shadingMapSize) ) )
greenOMap = np.dstack( (np.zeros(shadingMapSize), greenOMap, np.zeros(shadingMapSize) ) )
blueMap = np.dstack( (np.zeros(shadingMapSize), np.zeros(shadingMapSize), blueMap ) )

redImg = plt.figure(5)
doc_map(redImg, redMap, 0)
plt.title('Red lens shading map')

if args.save_figures:
  plt.savefig('red_shading.png',bbox_inches='tight')

greenEImg = plt.figure(6)
doc_map(greenEImg, greenEMap, 1)
plt.title('Green (even rows) lens shading map')

if args.save_figures:
  plt.savefig('green_e_shading.png',bbox_inches='tight')

greenOImg = plt.figure(7)
doc_map(greenOImg, greenOMap, 1)
plt.title('Green (odd rows) lens shading map')

if args.save_figures:
  plt.savefig('green_o_shading.png',bbox_inches='tight')

blueImg = plt.figure(8)
doc_map(blueImg, blueMap, 2)
plt.title('Blue lens shading map')

if args.save_figures:
  plt.savefig('blue_shading.png',bbox_inches='tight')

rgbImg = plt.figure(9)

rgbImg.clear()
plt.imshow(1/rgbMap,interpolation='bicubic')

axes = rgbImg.get_axes()[0]
axes.set_xticks(range(0, np.size(rgbMap, 1)))
axes.set_yticks(range(0, np.size(rgbMap, 0)))

plt.title('Image of uniform white wall (inverse shading map)')

if args.save_figures:
  plt.savefig('inv_shading.png',bbox_inches='tight')

# Rec. 709
x_rec709 = x_gamma
y_rec709 = np.where(x_rec709 <= 0.018, x_rec709 * 4.500, 1.099*x_rec709**0.45-0.099)

rec709_fig = plt.figure(10)
doc_plot(rec709_fig, x_rec709, y_rec709)

rec709_title = 'Rec. 709 tonemapping curve'
plt.title(rec709_title)
print rec709_title
doc_coeff(x_rec709, y_rec709)

if args.save_figures:
  plt.savefig('rec709_tonemap.png',bbox_inches='tight')


# Show figures

plt.show()