def lfp_align(self): # align light field lfp_obj = lfp_aligner.LfpAligner(self.lfp_img, self.cfg, self.sta, self.wht_img) lfp_obj.main() self.lfp_img_align = lfp_obj.lfp_img del lfp_obj
def main(): # program info print("\nPlenoptiCam v%s \n" % __version__) # create config object cfg = PlenopticamConfig() cfg.default_values() # parse options cfg = parse_options(sys.argv[1:], cfg) # instantiate status object sta = misc.PlenopticamStatus() sta.bind_to_interrupt(sys.exit) # set interrupt # force relative paths to be absolute cfg.params[cfg.lfp_path] = os.path.abspath(cfg.params[cfg.lfp_path]) cfg.params[cfg.cal_path] = os.path.abspath(cfg.params[cfg.cal_path]) # collect light field image file name(s) based on provided path if os.path.isdir(cfg.params[cfg.lfp_path]): lfp_filenames = [ f for f in os.listdir(cfg.params[cfg.lfp_path]) if f.lower().endswith(SUPP_FILE_EXT) ] cfg.params[cfg.lfp_path] = os.path.join(cfg.params[cfg.lfp_path], 'dummy.ext') elif not os.path.isfile(cfg.params[cfg.lfp_path]): lfp_filenames = [ misc.select_file(cfg.params[cfg.lfp_path], 'Select plenoptic image') ] else: lfp_filenames = [cfg.params[cfg.lfp_path]] if not cfg.params[cfg.cal_path]: # manual calibration data selection sta.status_msg( '\r Please select white image calibration source manually', cfg.params[cfg.opt_prnt]) # open selection window (at current lfp file directory) to set calibration folder path cfg.params[cfg.cal_path] = misc.select_file( cfg.params[cfg.lfp_path], 'Select calibration image') # provide number of found images to user print("\n %s Image(s) found" % len(lfp_filenames)) # cancel if file paths not provided sta.validate(checklist=lfp_filenames + [cfg.params[cfg.lfp_path]], msg='Canceled due to missing image file path') # iterate through light field image(s) for lfp_filename in sorted(lfp_filenames): # 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 lfp_obj = lfp_reader.LfpReader(cfg, sta) lfp_obj.main() lfp_img = lfp_obj.lfp_img del lfp_obj except Exception as e: misc.PlenopticamError(e) 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 obj = lfp_calibrator.CaliFinder(cfg, sta) obj.main() wht_img = obj.wht_bay del obj 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 cal_obj = lfp_calibrator.LfpCalibrator(wht_img, cfg, sta) cal_obj.main() cfg = cal_obj.cfg del cal_obj # load calibration data cfg.load_cal_data() # check if light field alignment has been done before if cfg.cond_lfp_align(): # align light field lfp_obj = lfp_aligner.LfpAligner(lfp_img, cfg, sta, wht_img) lfp_obj.main() lfp_obj = lfp_obj.lfp_img del lfp_obj # load previously computed light field alignment with open(os.path.join(cfg.exp_path, 'lfp_img_align.pkl'), 'rb') as f: lfp_img_align = pickle.load(f) # extract viewpoint data lfp_calibrator.CaliFinder(cfg).main() obj = lfp_extractor.LfpExtractor(lfp_img_align, cfg=cfg, sta=sta) obj.main() vp_img_arr = obj.vp_img_arr del obj # do refocusing if cfg.params[cfg.opt_refo]: obj = lfp_refocuser.LfpRefocuser(vp_img_arr, cfg=cfg, sta=sta) obj.main() del obj return True
sta.bind_to_interrupt(sys.exit) # set interrupt 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 cal_obj = lfp_calibrator.LfpCalibrator(wht_img, cfg, sta) cal_obj.main() cfg = cal_obj.cfg del cal_obj # load calibration data cfg.load_cal_data() if cfg.cond_lfp_align(): # align light field lfp_obj = lfp_aligner.LfpAligner(lfp_img, cfg, sta, wht_img) lfp_obj.main() lfp_obj = lfp_obj.lfp_img del lfp_obj # load previously computed light field alignment with open(os.path.join(cfg.exp_path, 'lfp_img_align.pkl'), 'rb') as f: lfp_img_align = pickle.load(f) start = time.time() # extract viewpoint data lfp_calibrator.CaliFinder(cfg).main() obj = lfp_extractor.LfpExtractor(lfp_img_align, cfg=cfg, sta=sta) obj.main()
def main(): # create config object cfg = PlenopticamConfig() cfg.default_values() cfg.reset_values() # parse options cfg = parse_options(sys.argv[1:], cfg) # instantiate status object sta = misc.PlenopticamStatus() sta.bind_to_interrupt(sys.exit) # set interrupt # select light field image(s) considering provided folder or file if os.path.isdir(cfg.params[cfg.lfp_path]): lfp_filenames = [ f for f in os.listdir(cfg.params[cfg.lfp_path]) if f.lower().endswith(SUPP_FILE_EXT) ] elif not os.path.isfile(cfg.params[cfg.lfp_path]): lfp_filenames = [ misc.select_file(cfg.params[cfg.lfp_path], 'Select plenoptic image') ] else: lfp_filenames = [cfg.params[cfg.lfp_path]] if not cfg.params[cfg.cal_path]: # open selection window (at current lfp file directory) to set calibration folder path cfg.params[cfg.cal_path] = misc.select_file( cfg.params[cfg.lfp_path], 'Select calibration image') # cancel if file paths not provided sta.validate(checklist=lfp_filenames + [cfg.params[cfg.lfp_path]], msg='Canceled due to missing image file path') # iterate through light field image(s) for lfp_filename in lfp_filenames: # change path to next filename cfg.params[cfg.lfp_path] = os.path.join( os.path.dirname(cfg.params[cfg.lfp_path]), lfp_filename) sta.status_msg(msg=cfg.params[cfg.lfp_path], opt=cfg.params[cfg.opt_prnt]) try: # decode light field image lfp_obj = lfp_reader.LfpReader(cfg, sta, cfg.params[cfg.lfp_path]) lfp_obj.main() lfp_img = lfp_obj.lfp_img del lfp_obj except Exception as e: misc.PlenopticamError(e) 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 obj = lfp_calibrator.CaliFinder(cfg, sta) obj.main() wht_img = obj.wht_img del obj else: # manual calibration data selection sta.status_msg( '\r Please select white image calibration source manually', cfg.params[cfg.opt_prnt]) # 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 cal_obj = lfp_calibrator.LfpCalibrator(wht_img, cfg, sta) cal_obj.main() cfg = cal_obj.cfg del cal_obj # load calibration data cfg.load_cal_data() # check if light field alignment has been done before if cfg.cond_lfp_align: # align light field lfp_obj = lfp_aligner.LfpAligner(lfp_img, cfg, sta, wht_img) lfp_obj.main() lfp_obj = lfp_obj.lfp_img del lfp_obj # load previously computed light field alignment with open(os.path.join(cfg.exp_path, 'lfp_img_align.pkl'), 'rb') as f: lfp_img_align = pickle.load(f) # export light field data lfp_calibrator.CaliFinder(cfg).main() exp_obj = lfp_extractor.LfpExtractor(lfp_img_align, cfg) exp_obj.main() del exp_obj
def main(): # parse options cfg = parse_options(sys.argv[1:]) # instantiate status object sta = misc.PlenopticamStatus() sta.bind_to_interrupt(sys.exit) # set interrupt # set calibration folder path cfg.params[cfg.cal_path] = "/Users/Admin/Pictures/Lytro_Illum/CalibFolder" # select light field image cfg.params[cfg.lfp_path] = misc.select_file(cfg.params[cfg.lfp_path], 'Select plenoptic image') # decode light field image lfp_obj = lfp_reader.LfpReader(cfg, sta, cfg.params[cfg.lfp_path]) lfp_obj.main() lfp_img = lfp_obj.lfp_img del lfp_obj # create output data folder misc.mkdir_p(cfg.params[cfg.lfp_path].split('.')[0], cfg.params[cfg.opt_prnt]) # check if light field alignment has been done before if not os.path.exists(os.path.join(cfg.params[cfg.lfp_path].split('.')[0], 'lfp_img_align.pkl')): # manual calibration data selection sta.status_msg('\r Please select white image calibration source manually', cfg.params[cfg.opt_prnt]) # open selection window (at directory where current lfp file is located) cfg.params[cfg.cal_path] = misc.select_file(cfg.params[cfg.lfp_path]) if os.path.isdir(cfg.params[cfg.cal_path]) or cfg.params[cfg.cal_path].endswith('.tar'): # automatic calibration data selection obj = lfp_calibrator.CaliFinder(cfg, sta) obj.main() wht_img = obj.wht_img del obj 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].endswith('json')) if meta_cond or cfg.params[cfg.opt_cali]: # perform centroid calibration cal_obj = lfp_calibrator.LfpCalibrator(wht_img, cfg, sta) cal_obj.main() cfg = cal_obj.cfg del cal_obj # load calibration data cfg.load_cal_data() # align light field lfp_obj = lfp_aligner.LfpAligner(lfp_img, cfg, sta, wht_img) lfp_obj.main() lfp_obj = lfp_obj.lfp_img del lfp_obj # load previously computed light field alignment lfp_img_align = pickle.load(open(os.path.join(cfg.params[cfg.lfp_path].split('.')[0], 'lfp_img_align.pkl'), 'rb')) # export light field data exp_obj = lfp_extractor.LfpExtractor(lfp_img_align, cfg) exp_obj.main() del exp_obj