Пример #1
0
    def test_lfp(self):

        # set config for unit test purposes
        cfg = PlenopticamConfig()
        cfg.params[cfg.opt_dbug] = True

        for fn_lfp, fn_wht in zip(self.fnames_lfp, self.fnames_wht):

            # update file paths and calibration data in config
            cfg.params[cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            cfg.params[cfg.cal_path] = os.path.join(self.fp, fn_wht)
            cfg.params[cfg.cal_meta] = os.path.splitext(
                cfg.params[cfg.cal_path])[0] + '.json'
            cfg.load_cal_data()

            # create folder (if it doesn't already exist)
            misc.mkdir_p(os.path.splitext(cfg.params[cfg.lfp_path])[0])

            # test light field alignment
            lfp_img = misc.load_img_file(cfg.params[cfg.lfp_path])
            lfp_obj = LfpAligner(lfp_img=lfp_img, cfg=cfg, sta=None)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            # test light field extraction
            lfp_obj = LfpExtractor(lfp_img_align=lfp_img, cfg=cfg, sta=None)
            ret_val = lfp_obj.main()
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)
Пример #2
0
    def test_lfp(self):

        # set config for unit test purposes
        sta = PlenopticamStatus()
        cfg = PlenopticamConfig()
        cfg.reset_values()
        cfg.params[cfg.opt_dbug] = False
        cfg.params[
            cfg.
            opt_prnt] = False  # prevent Travis CI to terminate after reaching 4MB logfile size

        for fn_lfp, fn_wht in zip(self.fnames_lfp, self.fnames_wht):

            # generate console output to prevent abort in Travis CI
            print(fn_lfp)

            # update file paths and calibration data in config
            cfg.params[cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            cfg.params[cfg.cal_path] = os.path.join(self.fp, fn_wht)
            cfg.params[cfg.cal_meta] = os.path.splitext(
                cfg.params[cfg.cal_path])[0] + '.json'
            cfg.load_cal_data()

            # create folder (if it doesn't already exist)
            mkdir_p(os.path.splitext(cfg.params[cfg.lfp_path])[0])

            # test light field alignment
            lfp_img = load_img_file(cfg.params[cfg.lfp_path])
            lfp_obj = LfpAligner(lfp_img=lfp_img, cfg=cfg, sta=sta)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            # test light field extraction
            lfp_obj = LfpExtractor(lfp_img_align=lfp_img, cfg=cfg, sta=sta)
            lfp_obj.main()
            vp_img_arr = lfp_obj.vp_img_arr
            del lfp_obj

            lfp_obj = LfpRefocuser(vp_img_arr=vp_img_arr, cfg=cfg, sta=sta)
            lfp_obj.main()
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)
Пример #3
0
    def test_custom_lfp(self):

        for fn_lfp, fn_wht in zip(self.loader.opex_fnames_lfp,
                                  self.loader.opex_fnames_wht):

            # generate console output to prevent abort in Travis CI
            print(fn_lfp)

            # update file paths and calibration data in config
            self.cfg.params[self.cfg.lfp_path] = join(self.fp, fn_lfp)
            self.cfg.params[self.cfg.cal_path] = join(self.fp, fn_wht)
            self.cfg.params[self.cfg.cal_meta] = splitext(
                self.cfg.params[self.cfg.cal_path])[0] + '.json'
            self.cfg.load_cal_data()

            # create folder (if it doesn't already exist)
            mkdir_p(splitext(self.cfg.params[self.cfg.lfp_path])[0])

            # test light field alignment
            lfp_img = load_img_file(self.cfg.params[self.cfg.lfp_path])
            lfp_obj = LfpAligner(lfp_img=lfp_img, cfg=self.cfg, sta=self.sta)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            # test light field extraction
            lfp_obj = LfpExtractor(lfp_img_align=lfp_img,
                                   cfg=self.cfg,
                                   sta=self.sta)
            ret_val = lfp_obj.main()
            vp_img_arr = lfp_obj.vp_img_arr
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            lfp_obj = LfpRefocuser(vp_img_arr=vp_img_arr,
                                   cfg=self.cfg,
                                   sta=self.sta)
            ret_val = lfp_obj.main()
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)
Пример #4
0
    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)
                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)

            # load calibration data
            self.cfg.load_cal_data()

            # write centroids as png file
            if wht_img is not None:
                obj = CentroidDrawer(wht_img,
                                     self.cfg.calibs[self.cfg.mic_list],
                                     self.cfg)
                ret = obj.write_centroids_img(fn='testcase_wht_img+mics.png')
                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
Пример #5
0
    def test_illum(self):

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

        # skip concole output message (prevent Travis from terminating due to reaching 4MB logfile size)
        cfg.params[cfg.opt_prnt] = False

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

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

        for lfp_file in lfp_list:

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

            # decode light field image
            lfp_obj = LfpReader(cfg, sta)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            self.assertEqual(True, ret_val)

            # create output data folder
            mkdir_p(cfg.exp_path, cfg.params[cfg.opt_prnt])

            if not cfg.cond_meta_file():
                # automatic calibration data selection
                obj = CaliFinder(cfg, sta)
                ret_val = obj.main()
                wht_img = obj.wht_bay
                del obj

                self.assertEqual(True, ret_val)

            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 = LfpCalibrator(wht_img, cfg, sta)
                ret_val = cal_obj.main()
                cfg = cal_obj.cfg
                del cal_obj

                self.assertEqual(True, ret_val)

            # 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 = LfpAligner(lfp_img, cfg, sta, wht_img)
                ret_val = lfp_obj.main()
                lfp_obj = lfp_obj.lfp_img
                del lfp_obj

                self.assertEqual(True, ret_val)

            # 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
            CaliFinder(cfg).main()
            obj = LfpExtractor(lfp_img_align, cfg=cfg, sta=sta)
            ret_val = obj.main()
            vp_img_arr = obj.vp_img_arr
            del obj

            self.assertEqual(True, ret_val)

            # do refocusing
            if cfg.params[cfg.opt_refo]:
                obj = LfpRefocuser(vp_img_arr, cfg=cfg, sta=sta)
                ret_val = obj.main()
                del obj

            self.assertEqual(True, ret_val)

        return True
Пример #6
0
    def test_illum(self):

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

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

        # compute 3x3 viewpoints only (to reduce computation time)
        cfg.params[cfg.ptc_leng] = 3

        # skip progress prints (prevent Travis from terminating due to reaching 4MB logfile size)
        sta.prog_opt = False

        # print current process message (to prevent Travis from stopping after 10 mins)
        cfg.params[cfg.opt_prnt] = True

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

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

        for lfp_file in lfp_list:

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

            # decode light field image
            obj = LfpReader(cfg, 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(cfg.exp_path, cfg.params[cfg.opt_prnt])

            if not cfg.cond_meta_file():
                # automatic calibration data selection
                obj = CaliFinder(cfg, 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 (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
                obj = LfpCalibrator(wht_img, cfg, sta)
                ret = obj.main()
                cfg = obj.cfg
                del obj

                self.assertEqual(True, ret)

            # load calibration data
            cfg.load_cal_data()

            # write centroids as png file
            if wht_img is not None:
                obj = CentroidDrawer(wht_img, cfg.calibs[cfg.mic_list], cfg)
                ret = obj.write_centroids_img(
                    fn=os.path.join(cfg.exp_path, 'wht_img+mics.png'))
                del obj

                self.assertEqual(True, ret)

            #  check if light field alignment has been done before
            if cfg.cond_lfp_align():
                # align light field
                obj = LfpAligner(lfp_img, cfg, sta, wht_img)
                ret = obj.main()
                del obj

                self.assertEqual(True, ret)

            # 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
            CaliFinder(cfg).main()
            obj = LfpExtractor(lfp_img_align, cfg=cfg, sta=sta)
            ret = obj.main()
            vp_img_arr = obj.vp_img_arr
            del obj

            self.assertEqual(True, ret)

            # do refocusing
            if cfg.params[cfg.opt_refo]:
                obj = LfpRefocuser(vp_img_arr, cfg=cfg, sta=sta)
                ret = obj.main()
                del obj

            self.assertEqual(True, ret)

        return True