How to use the plenopticam.misc.load_img_file function in plenopticam

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 / 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 / scripts / metrics / brisque_analysis_flip.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 = load_img_file(os.path.join(fp, file))

                # extract image tile
                if crop_opt:
                    img = img[2:-2, 2:-2, ...] if file.endswith('Thumb.png') else img
                    cy, cx = [x//2 for x in img.shape[:2]]
                    hh, hw = [x//10 for x in img.shape[:2]]
                    img_tile = img[cy-hh:cy+hh+1, cx-hw:cx+hw+1]
                else:
                    img_tile = img

                score = brisque_metric(Normalizer(img_tile).uint8_norm())
                scores.append(score)
                print(file+': %s' % scores[-1])

            #brisq.get_feature(os.path.join(fp, file))
github hahnec / plenopticam / plenopticam / gui / ple_viewer.py View on Github external
def get_list(img_dir, vp=1):

    from plenopticam import misc
    import numpy as np

    dir_list = os.listdir(img_dir)
    dir_list.sort()
    img_list = []
    for i in dir_list:
        img_path = os.path.join(img_dir, i)
        ext = img_path.split('.')[::-1][0].lower()
        if ext in GENERIC_EXTS:

            # load image
            img = misc.load_img_file(img_path)

            # convert to uint8 if necessary
            img = Normalizer(img).uint8_norm() if str(img.dtype) != 'uint8' else img

            # append to image list
            img_list.append((i, img))

    # sort image list by indices in file names
    img_tuples = sorted(img_list, key=lambda k: idx_str_sort(k[0], 1 if vp else 0))
    _, img_list = zip(*img_tuples)

    if vp:
        vp_dim = int(np.sqrt(len(img_list)))
        img_list = np.reshape(img_list, newshape=(vp_dim, vp_dim) + img_list[0].shape, order='C')

    return img_list
github hahnec / plenopticam / plenopticam / scripts / metrics / blur_metric.py View on Github external
fp_ours = '/Volumes/SD CARD 1/IEEEtran/img/refo_upscale_7px'
    else:
        fp_lytro = ''
        fp_ours = ''

    # loop over directories
    for fp in [fp_lytro, fp_ours]:
        slice_fns = [f for f in os.listdir(fp) if f.__contains__('crop')]

        s_list = list()

        # loop over filenames in directory
        for slice_fn in slice_fns:

            # load cropped slice
            img_tile = misc.load_img_file(os.path.join(fp, slice_fn))

            # remove alpha channel if present
            img_tile = img_tile[..., :3]

            # rescale tile for fair comparison
            img_tile = misc.img_resize(img_tile, 2.28122448) if fp.__contains__('refo_lytro') else img_tile

            # store results
            s_list.append((slice_fn, blur_metric(img_tile), michelson_contrast(img_tile)))

        for s in s_list:
            print(s)
github hahnec / plenopticam / plenopticam / lfp_reader / top_level.py View on Github external
self.decode_lytro_file()
            except FileNotFoundError:
                # print status
                self.sta.status_msg('{0} not found'.format(os.path.basename(self._lfp_path)), self.cfg.params[self.cfg.opt_prnt])
                self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])
                self.sta.error = True
            except Exception as e:
                # unrecognized LFP file type
                if not self._json_dict:
                    raise LfpTypeError(e, cfg=self.cfg)
                else:
                    raise PlenopticamError(e, cfg=self.cfg, sta=self.sta)
        else:
            try:
                # read and decode generic image file type
                self._lfp_img = misc.load_img_file(self._lfp_path)
                # inverse sRGB conversion
                self._lfp_img = GammaConverter().srgb_conv(self._lfp_img, inverse=True)
            except TypeError:
                self.sta.status_msg('File type not recognized')
                self.sta.error = True
                return False

            try:
                # try to load json file (if present)
                json_dict = self.cfg.load_json(self._lfp_path)
                self.cfg.lfpimg = LfpDecoder.filter_lfp_json(json_dict, self.cfg.lfp_img)
            except:
                pass

        # write json file
        self.cfg.save_params()
github hahnec / plenopticam / plenopticam / bin / cli_script.py View on Github external
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

        # load calibration data
        cfg.load_cal_data()

        #  check if light field alignment has been done before
        if cfg.cond_lfp_align():