Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ret = obj.main()
# use third of original image size (to prevent Travis from stopping due to memory error)
crop_h, crop_w = obj.lfp_img.shape[0] // 3, obj.lfp_img.shape[1] // 3
crop_h, crop_w = crop_h + crop_h % 2, crop_w + crop_w % 2 # use even number for correct Bayer arrangement
lfp_img = obj.lfp_img[crop_h:-crop_h, crop_w:-crop_w]
del obj
self.assertEqual(True, ret)
# create output data folder
mkdir_p(self.cfg.exp_path, self.cfg.params[self.cfg.opt_prnt])
if not self.cfg.cond_meta_file():
# automatic calibration data selection
obj = CaliFinder(self.cfg, self.sta)
ret = obj.main()
wht_img = obj.wht_bay[crop_h:-crop_h, crop_w:-crop_w] if obj.wht_bay is not None else obj.wht_bay
del obj
self.assertEqual(True, ret)
meta_cond = not (exists(self.cfg.params[self.cfg.cal_meta]) and self.cfg.params[self.cfg.cal_meta].lower().endswith('json'))
if meta_cond or self.cfg.params[self.cfg.opt_cali]:
# perform centroid calibration
obj = LfpCalibrator(wht_img, self.cfg, self.sta)
ret = obj.main()
self.cfg = obj.cfg
del obj
self.assertEqual(True, ret)
# check if light field alignment has been done before
if self.cfg.cond_lfp_align():
# align light field
obj = LfpAligner(lfp_img, self.cfg, self.sta, wht_img)
ret = obj.main()
del obj
self.assertEqual(True, ret)
# load previously computed light field alignment
with open(join(self.cfg.exp_path, 'lfp_img_align.pkl'), 'rb') as f:
lfp_img_align = pickle.load(f)
# extract viewpoint data
CaliFinder(self.cfg).main()
obj = LfpExtractor(lfp_img_align, cfg=self.cfg, sta=self.sta)
ret = obj.main()
vp_img_arr = obj.vp_img_linear
del obj
self.assertEqual(True, ret)
# do refocusing
if self.cfg.params[self.cfg.opt_refo]:
obj = LfpRefocuser(vp_img_arr, cfg=self.cfg, sta=self.sta)
ret = obj.main()
del obj
self.assertEqual(True, ret)
return True
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
meta_cond = not (os.path.exists(cfg.params[cfg.cal_meta]) and cfg.params[cfg.cal_meta].lower().endswith('json'))
if meta_cond or cfg.params[cfg.opt_cali]:
# perform centroid calibration
calibrator = lfp_calibrator.LfpCalibrator(wht_img, cfg, sta)
calibrator.main()
cfg = calibrator.cfg
cfg.params[cfg.opt_cali] = True
cfg.params[cfg.opt_rota] = True
cfg.params[cfg.opt_dbug] = False
cfg.params[cfg.cal_meth] = 'grid-fit'
cal_opt = False
if cal_opt:
# decode light field image
lfp_obj = lfp_reader.LfpReader(cfg)
lfp_obj.main()
lfp_img = lfp_obj.lfp_img[:, :-16]
del lfp_obj
# automatic calibration data selection
obj = lfp_calibrator.CaliFinder(cfg)
obj.main()
wht_img = obj.wht_bay[:, :-16]
del obj
if cal_opt:
# perform centroid calibration
cal_obj = lfp_calibrator.LfpCalibrator(wht_img, cfg)
cal_obj.main()
cfg = cal_obj.cfg
del cal_obj
else:
# convert Bayer to RGB representation
if len(wht_img.shape) == 2 and 'bay' in cfg.lfpimg:
# perform color filter array management and obtain rgb image
cfa_obj = CfaProcessor(bay_img=wht_img, cfg=cfg)
cfa_obj.bay2rgb()
cfg = calibrator.cfg
# load calibration data
cfg.load_cal_data()
# check if light field alignment has been done before
if cfg.cond_lfp_align():
# align light field
aligner = lfp_aligner.LfpAligner(lfp_img, cfg, sta, wht_img)
aligner.main()
lfp_img_align = aligner.lfp_img
else:
lfp_img_align = None
# extract viewpoint data
lfp_calibrator.CaliFinder(cfg).main()
extractor = lfp_extractor.LfpExtractor(lfp_img_align, cfg=cfg, sta=sta)
extractor.main()
# do refocusing
if cfg.params[cfg.opt_refo]:
extractor = lfp_refocuser.LfpRefocuser(extractor.vp_img_linear, cfg=cfg, sta=sta)
extractor.main()
return True
def auto_find(self):
if self.wht_img is None:
# find calibration file automatically
obj = lfp_calibrator.CaliFinder(self.cfg, self.sta)
obj.main()
self.wht_img = obj._wht_bay
del obj
# white image demosaicing (when light field image is given as RGB)
if self.wht_img is not None and len(self.lfp_img.shape) == 3:
from plenopticam.lfp_aligner.cfa_processor import CfaProcessor
cfa_obj = CfaProcessor(bay_img=self.wht_img, cfg=self.cfg, sta=self.sta)
cfa_obj.bay2rgb()
self.wht_img = cfa_obj.rgb_img
del cfa_obj