Skip to content

Commit d83ff0a

Browse files
davidplowmannaushir
authored andcommitted
utils: raspberrypi: ctt: Fix NaNs in chromatic aberration tables
NaNs can appear if no black dots can be found and analysed in a particular region of the calibration image. There needs to be at least one such dot in every 8x8 cell covering the image. This is now detected, and an error message issued. No CAC tables are generated, so CAC is disabled. Signed-off-by: David Plowman <[email protected]>
1 parent be44de8 commit d83ff0a

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

utils/raspberrypi/ctt/ctt.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,12 @@ def cac_cal(self, do_alsc_colour):
198198
"""
199199
Write output to json
200200
"""
201-
self.json['rpi.cac']['cac'] = cacs
202-
self.log += '\nCAC calibration written to json file'
203-
print('Finished CAC calibration')
201+
if cacs:
202+
self.json['rpi.cac']['cac'] = cacs
203+
self.log += '\nCAC calibration written to json file'
204+
print('Finished CAC calibration')
205+
else:
206+
self.log += "\nCAC calibration failed"
204207

205208

206209
"""

utils/raspberrypi/ctt/ctt_cac.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,29 @@ def shifts_to_yaml(red_shift, blue_shift, image_dimensions, output_grid_size=9):
108108
ybsgrid[xgridloc][ygridloc].append(blue_shift[3])
109109

110110
# Now calculate the average pixel shift for each square in the grid
111+
grid_incomplete = False
111112
for x in range(output_grid_size - 1):
112113
for y in range(output_grid_size - 1):
113-
xrgrid[x, y] = np.mean(xrsgrid[x][y])
114-
yrgrid[x, y] = np.mean(yrsgrid[x][y])
115-
xbgrid[x, y] = np.mean(xbsgrid[x][y])
116-
ybgrid[x, y] = np.mean(ybsgrid[x][y])
114+
if xrsgrid[x][y]:
115+
xrgrid[x, y] = np.mean(xrsgrid[x][y])
116+
else:
117+
grid_incomplete = True
118+
if yrsgrid[x][y]:
119+
yrgrid[x, y] = np.mean(yrsgrid[x][y])
120+
else:
121+
grid_incomplete = True
122+
if xbsgrid[x][y]:
123+
xbgrid[x, y] = np.mean(xbsgrid[x][y])
124+
else:
125+
grid_incomplete = True
126+
if ybsgrid[x][y]:
127+
ybgrid[x, y] = np.mean(ybsgrid[x][y])
128+
else:
129+
grid_incomplete = True
130+
131+
if grid_incomplete:
132+
raise RuntimeError("\nERROR: CAC measurements do not span the image!"
133+
"\nConsider using improved CAC images, or remove them entirely.\n")
117134

118135
# Next, we start to interpolate the central points of the grid that gets passed to the tuning file
119136
input_grids = np.array([xrgrid, yrgrid, xbgrid, ybgrid])
@@ -219,7 +236,12 @@ def cac(Cam):
219236
# tuning file
220237
print("\nCreating output grid")
221238
Cam.log += '\nCreating output grid'
222-
rx, ry, bx, by = shifts_to_yaml(red_shift, blue_shift, image_size)
239+
try:
240+
rx, ry, bx, by = shifts_to_yaml(red_shift, blue_shift, image_size)
241+
except RuntimeError as e:
242+
print(str(e))
243+
Cam.log += "\nCAC correction failed! CAC will not be enabled."
244+
return {}
223245

224246
print("CAC correction complete!")
225247
Cam.log += '\nCAC correction complete!'

0 commit comments

Comments
 (0)