Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# reset
self.var_init()
# status update
self.sta.status_msg('Loading data', self.cfg.params[self.cfg.opt_prnt])
self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])
# disable button activity
self.toggle_btn_list(self.all_btn_list)
self.cmd_wid.btn_list[3].config(text='Stop')
# read light field photo and calibration source paths
self.fetch_paths()
# remove output folder if option is set
misc.rmdir_p(self.cfg.exp_path) if self.cfg.params[self.cfg.dir_remo] else None
# remove calibrated light-field if calibration or devignetting option is set
if self.cfg.params[self.cfg.opt_cali] or self.cfg.params[self.cfg.opt_vign]:
misc.rm_file(join(self.cfg.exp_path, 'lfp_img_align.pkl'))
if self.cfg.params[self.cfg.opt_cali]:
misc.rm_file(self.cfg.params[self.cfg.cal_meta])
# create output data folder (prevent override)
misc.mkdir_p(self.cfg.exp_path, self.cfg.params[self.cfg.opt_prnt])
# put tasks in the job queue to be run
for task_info in (
(self.load_lfp, self.cfg.cond_load_limg, self.cfg.params[self.cfg.lfp_path]),
(self.auto_find, self.cfg.cond_auto_find),
(self.load_lfp, self.cfg.cond_load_wimg, self.cfg.params[self.cfg.cal_path], True),
(self.cal, self.cfg.cond_perf_cali),
# print status
self.sta.status_msg('Debayering', self.cfg.params[self.cfg.opt_prnt])
self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])
# Bayer to RGB conversion
if method == 0:
self._rgb_img = demosaicing_CFA_Bayer_bilinear(self._bay_img, self.cfg.lfpimg['bay'])
elif method == 1:
self._rgb_img = demosaicing_CFA_Bayer_Malvar2004(self._bay_img, self.cfg.lfpimg['bay'])
else:
self._rgb_img = demosaicing_CFA_Bayer_Menon2007(self._bay_img, self.cfg.lfpimg['bay'])
# normalize image
min = np.percentile(self._rgb_img, 0.05)
max = np.max(self.rgb_img)
self._rgb_img = misc.Normalizer(self._rgb_img, min=min, max=max).type_norm()
# update status message
self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])
return True
# change path to next filename
cfg.params[cfg.lfp_path] = os.path.join(os.path.dirname(cfg.params[cfg.lfp_path]), lfp_filename)
print(cfg.params[cfg.lfp_path])
sta.status_msg(msg='Process file '+lfp_filename, opt=cfg.params[cfg.opt_prnt])
# remove output folder if option is set
misc.rmdir_p(cfg.exp_path) if cfg.params[cfg.dir_remo] else None
try:
# decode light field image
aligner = lfp_reader.LfpReader(cfg, sta)
aligner.main()
lfp_img = aligner.lfp_img
except Exception as e:
misc.PlenopticamError(e, cfg=cfg, sta=sta)
continue
# create output data folder
misc.mkdir_p(cfg.exp_path, cfg.params[cfg.opt_prnt])
if cfg.cond_auto_find():
# automatic calibration data selection
extractor = lfp_calibrator.CaliFinder(cfg, sta)
extractor.main()
wht_img = extractor.wht_bay
else:
# load white image calibration file
wht_img = misc.load_img_file(cfg.params[cfg.cal_path])
# save settings configuration
cfg.save_params()
# perform calibration if previously computed calibration data does not exist
def main(self):
# check interrupt status
if self.sta.interrupt:
return False
# apply auto white balance gains while considering image highlights
self.safe_bayer_awb()
# debayer to rgb image
if 'bay' in self.cfg.lfpimg.keys() and len(self._bay_img.shape) == 2:
self.bay2rgb(2)
# convert to uint16
self._rgb_img = misc.Normalizer(self._rgb_img).uint16_norm()
return True
def main(self):
# check interrupt status
if self.sta.interrupt:
return False
# remove hexagonal artifact
if self.cfg.calibs[self.cfg.pat_type] == 'hex':
self.proc_vp_arr(self.ver_hex_bulge, msg='Hexagonal artifact removal')
# normalize light-field
self.vp_img_arr = misc.Normalizer(self.vp_img_arr).uint16_norm()
return True