Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions utils/raspberrypi/ctt/ctt.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,15 @@ def run_ctt(json_output, directory, config, log_output, json_template, grid_size
try:
Cam = Camera(json_output, json=json_template)
Cam.log_user_input(json_output, directory, config, log_output)
if alsc_only:
disable = set(Cam.json.keys()).symmetric_difference({"rpi.alsc"})
Cam.disable = disable
Cam.plot = plot
Cam.add_imgs(directory, mac_config, blacklevel)
except FileNotFoundError:
raise ArgError('\n\nError: Input image directory not found!')
if len(Cam.imgs) == 0 and len(Cam.imgs_cac) == 0 and len(Cam.imgs_alsc) > 0:
alsc_only = True
if alsc_only:
disable = set(Cam.json.keys()).symmetric_difference({"rpi.alsc"})
Cam.disable = disable
Cam.plot = plot

"""
preform calibrations as long as check_imgs returns True
Expand Down
14 changes: 7 additions & 7 deletions utils/raspberrypi/ctt/ctt_alsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0)
cb = cb/np.min(cb)
cg = cv2.medianBlur(cg, 3).astype('float64')
cg = cg/np.min(cg)
cg = [min(v, max_gain) for v in cg.flatten()] # never exceed the max luminance gain
cg_clamp = [min(v, max_gain) for v in cg.flatten()] # never exceed the max luminance gain

"""
debugging code showing 2D surface plot of vignetting. Quite useful for
Expand All @@ -183,7 +183,7 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0)
# print(Img.str)
plt.show()

return Img.col, cr.flatten(), cb.flatten(), cg, (w, h, dx, dy)
return Img.col, cr.flatten(), cb.flatten(), cg_clamp, (w, h, dx, dy)

else:
"""
Expand All @@ -193,17 +193,17 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0)
cg = np.reshape(1/g, (grid_h, grid_w)).astype('float32')
cg = cv2.medianBlur(cg, 3).astype('float64')
cg = cg/np.min(cg)
cg = [min(v, max_gain) for v in cg.flatten()] # never exceed the max luminance gain
cg_clamp = [min(v, max_gain) for v in cg.flatten()] # never exceed the max luminance gain

if plot:
hf = plt.figure(figssize=(8, 8))
hf = plt.figure(figsize=(8, 8))
ha = hf.add_subplot(1, 1, 1, projection='3d')
X, Y = np.meashgrid(range(grid_w), range(grid_h))
X, Y = np.meshgrid(range(grid_w), range(grid_h))
ha.plot_surface(X, -Y, cg, cmap=cm.coolwarm, linewidth=0)
ha.set_title('ALSC Plot (Luminance only!)\nImg: {}\n\ncg').format(Img.str)
ha.set_title('ALSC Plot (Luminance only!)\nImg: {}\n\ncg'.format(Img.str))
plt.show()

return Img.col, None, None, cg.flatten(), (w, h, dx, dy)
return Img.col, None, None, cg_clamp, (w, h, dx, dy)


"""
Expand Down
22 changes: 17 additions & 5 deletions utils/raspberrypi/ctt/ctt_image_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,24 +322,35 @@ def dng_load_image(Cam, im_str):
photo = "Image"
Img.pad = 0
Img.h = metadata[f'Exif.{subimage}.ImageLength'].value
white = metadata[f'Exif.{subimage}.WhiteLevel'].value
try:
white = metadata[f'Exif.{subimage}.WhiteLevel'].value
except:
white = (1 << Img.sigbits) - 1
Img.sigbits = int(white).bit_length()
Img.fmt = (Img.sigbits - 4) // 2
Img.exposure = int(metadata[f'Exif.{photo}.ExposureTime'].value * 1000000)
Img.againQ8 = metadata[f'Exif.{photo}.ISOSpeedRatings'].value * 256 / 100
Img.againQ8_norm = Img.againQ8 / 256
Img.camName = metadata['Exif.Image.Model'].value
Img.blacklevel = int(metadata[f'Exif.{subimage}.BlackLevel'].value[0])
blacks = metadata[f'Exif.{subimage}.BlackLevel'].value
try:
Img.blacklevel = int(blacks[0])
except TypeError:
Img.blacklevel = int(blacks)
Img.blacklevel_16 = Img.blacklevel << (16 - Img.sigbits)
bayer_case = {
'0 1 1 2': (0, (0, 1, 2, 3)),
'1 2 0 1': (1, (2, 0, 3, 1)),
'2 1 1 0': (2, (3, 2, 1, 0)),
'1 0 2 1': (3, (1, 0, 3, 2))
}
cfa_pattern = metadata[f'Exif.{subimage}.CFAPattern'].value
Img.pattern = bayer_case[cfa_pattern][0]
Img.order = bayer_case[cfa_pattern][1]
try:
cfa_pattern = metadata[f'Exif.{subimage}.CFAPattern'].value
Img.pattern = bayer_case[cfa_pattern][0]
Img.order = bayer_case[cfa_pattern][1]
except:
Img.pattern = 128
Img.order = (0, 1, 2, 3) # dummy order for mono images

# Now use RawPy tp get the raw Bayer pixels
raw_im = raw.imread(im_str)
Expand All @@ -358,6 +369,7 @@ def dng_load_image(Cam, im_str):
Cam.log += '\nERROR: DNG file does not exist or is incompatible'
raise

Img.str = im_str
return Img


Expand Down