How to use plenopticam - 10 common examples

To help you get started, we’ve selected a few plenopticam examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hahnec / plenopticam / tests / unit_test_illum.py View on Github external
print('\nCompute image %s' % basename(self.cfg.params[self.cfg.lfp_path]))

            # decode light field image
            obj = LfpReader(self.cfg, self.sta)
            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
github hahnec / plenopticam / tests / unit_test_illum.py View on Github external
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)
github hahnec / plenopticam / tests / unit_test_illum.py View on Github external
def test_illum(self):

        # use pre-loaded calibration dataset
        wht_list = [file for file in listdir(self.fp) if file.startswith('caldata')]
        lfp_list = [file for file in listdir(self.fp) if file.endswith(('lfr', 'lfp'))]

        self.cfg.params[self.cfg.cal_path] = join(self.fp, wht_list[0])

        for lfp_file in lfp_list:

            self.cfg.params[self.cfg.lfp_path] = join(self.fp, lfp_file)
            print('\nCompute image %s' % basename(self.cfg.params[self.cfg.lfp_path]))

            # decode light field image
            obj = LfpReader(self.cfg, self.sta)
            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)
github hahnec / plenopticam / plenopticam / scripts / metrics / recolour_analysis.py View on Github external
score_series = list()
    for i, target_folder in enumerate(target_folders):
        fp = os.path.join(path, target_folder)

        files = [f for f in os.listdir(fp) if f.endswith(exts)]
        files.sort()

        scores = list()
        for file in files:

            # skip file if missing
            if os.path.splitext(file)[0].split('_')[0] not in skip_list:

                img_ref = load_img_file(os.path.join(fp, file))
                if target_folder.startswith('thumb_collection'):
                    img_src = load_img_file(os.path.join(fp, 'other_views', os.path.splitext(file)[0]+'_2_7'+'.png'))
                else:
                    img_src = load_img_file(os.path.join(fp, 'other_views', file.split('__')[0]+'28__'+file.split('__')[1]))

                score = hist_dist(img_ref, img_src)
                scores.append(score)
                print(file+': %s' % scores[-1])

        label = target_folder.split('_')[-1].replace('_', '-')
        #label = target_folder.split('_')[0]
        x_range = [x + (i - len(target_folders) // 2) * width for x in list(range(len(scores)))]  # range(len(scores))#
        plt.bar(x_range, scores, width,
                label=next(labelcycler), linestyle=next(linecycler))#, marker=next(markercycler))

        score_series.append(scores)

    # tick labels
github hahnec / plenopticam / plenopticam / scripts / metrics / recolour_analysis.py View on Github external
crop_opt = False

    score_series = list()
    for i, target_folder in enumerate(target_folders):
        fp = os.path.join(path, target_folder)

        files = [f for f in os.listdir(fp) if f.endswith(exts)]
        files.sort()

        scores = list()
        for file in files:

            # skip file if missing
            if os.path.splitext(file)[0].split('_')[0] not in skip_list:

                img_ref = load_img_file(os.path.join(fp, file))
                if target_folder.startswith('thumb_collection'):
                    img_src = load_img_file(os.path.join(fp, 'other_views', os.path.splitext(file)[0]+'_2_7'+'.png'))
                else:
                    img_src = load_img_file(os.path.join(fp, 'other_views', file.split('__')[0]+'28__'+file.split('__')[1]))

                score = hist_dist(img_ref, img_src)
                scores.append(score)
                print(file+': %s' % scores[-1])

        label = target_folder.split('_')[-1].replace('_', '-')
        #label = target_folder.split('_')[0]
        x_range = [x + (i - len(target_folders) // 2) * width for x in list(range(len(scores)))]  # range(len(scores))#
        plt.bar(x_range, scores, width,
                label=next(labelcycler), linestyle=next(linecycler))#, marker=next(markercycler))

        score_series.append(scores)
github hahnec / plenopticam / plenopticam / lfp_calibrator / pitch_estimator.py View on Github external
def _crop_img(self, CR=1):

        # crop image (for computational speed-up and smaller region of interest)
        S = self._img.shape[0]//2
        self._top_img = self._img[S-S//CR:S+S//CR-1, S-S//CR:S+S//CR-1].copy().astype(np.float64)

        # darken image edges to exclude micro images at border
        self._top_img *= create_gauss_kernel(length=S // CR * 2 - 1, sigma=S // CR // 2)

        return True
github hahnec / plenopticam / tests / unit_test_gui.py View on Github external
def setUp(self):
        self.root = tk.Tk()
        self.cfg = PlenopticamConfig()
        self.sta = PlenopticamStatus()
        self.root.cfg = self.cfg
        self.root.sta = self.sta
        self.set_file_path()
        self.pump_events()
github hahnec / plenopticam / tests / unit_test_illum.py View on Github external
def setUp(self):

        # instantiate config and status objects
        self.cfg = PlenopticamConfig()
        self.cfg.default_values()
        self.sta = PlenopticamStatus()

        # enable options in config to cover more algorithms in tests
        self.cfg.params[self.cfg.cal_meth] = 'grid-fit'
        self.cfg.params[self.cfg.opt_vign] = True
        self.cfg.params[self.cfg.opt_rota] = True
        self.cfg.params[self.cfg.opt_refi] = True
        self.cfg.params[self.cfg.opt_pflu] = True
        self.cfg.params[self.cfg.opt_arti] = True
        self.cfg.params[self.cfg.opt_lier] = True
        self.cfg.params[self.cfg.opt_cont] = True
        self.cfg.params[self.cfg.opt_awb_] = True
        self.cfg.params[self.cfg.opt_sat_] = True
        self.cfg.params[self.cfg.opt_dbug] = True
        self.cfg.params[self.cfg.ran_refo] = [0, 1]

        # compute 3x3 viewpoints only (to reduce computation time)
github hahnec / plenopticam / tests / unit_test_cli.py View on Github external
def setUp(self):

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = True
        self.cfg.params[self.cfg.opt_prnt] = True
github hahnec / plenopticam / tests / unit_test_gui.py View on Github external
def setUp(self):
        self.root = tk.Tk()
        self.cfg = PlenopticamConfig()
        self.sta = PlenopticamStatus()
        self.root.cfg = self.cfg
        self.root.sta = self.sta
        self.set_file_path()
        self.pump_events()