How to use the plenopticam.misc.img_resize 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 / lfp_refocuser / lfp_shiftandsum.py View on Github external
self.sta.progress(percentage, self.cfg.params[self.cfg.opt_prnt])

            # crop refocused image for consistent image dimensions
            crop = int(overlap/2)
            final_img = img_slice[crop:-crop, crop:-crop, :] if (a != 0) else img_slice

            # write upscaled version to hard drive
            if self.cfg.params[self.cfg.opt_refi]:
                upscale_img = LfpContrast().auto_hist_align(final_img.copy(), ref_img=final_img, opt=True)
                upscale_img = GammaConverter().srgb_conv(img=upscale_img)
                fname = np.round(a/patch_len, 2)
                LfpExporter(cfg=self.cfg, sta=self.sta).save_refo_slice(fname, upscale_img, string='upscale_')
                del upscale_img

            # spatially downscale image to original resolution (less memory required)
            final_img = misc.img_resize(final_img, 1./factor) if factor > 1 else final_img

            self._refo_stack.append(final_img)

        return True
github hahnec / plenopticam / plenopticam / scripts / metrics / blur_metric.py View on Github external
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 / scripts / metrics / refo_metrics.py View on Github external
# iterate through directories
    for set in [(fp_lytro, coords_lists_lytro), (fp_ours, coords_lists_pcam)]:

        fp, coords_lists = set

        img_tiles, slice_fns = crop_imgs(fp, coords_lists)

        # iterate through file names in directory
        for img_tile, slice_fn in zip(img_tiles, slice_fns):

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

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

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

    for s in s_list:
        print(s)

    s_arr = np.asarray(s_list)
    np.save('refo_metrics', s_list)
github hahnec / plenopticam / plenopticam / lfp_refocuser / lfp_shiftandsum.py View on Github external
# divide intensity to prevent clipping in shift and sum process
        self._vp_img_arr /= patch_len

        # iterate through refocusing parameter a
        ran_refo = self.cfg.params[self.cfg.ran_refo]
        a_list = tuple([factor*a for a in ran_refo]) if self.cfg.params[self.cfg.opt_refi] else ran_refo
        for a in range(*a_list):

            overlap = abs(a) * (patch_len - 1)
            img_slice = np.zeros(np.append(np.array(self._vp_img_arr.shape[2:-1]) * factor + [overlap, overlap], 3))
            for j in range(patch_len):
                for i in range(patch_len):

                    # perform sub-pixel refinement if required
                    vp_img = misc.img_resize(self._vp_img_arr[j, i], factor) if factor > 1 else self._vp_img_arr[j, i]

                    # get viewpoint padding for each border
                    tb = (abs(a) * j, abs(a) * (patch_len - 1 - j))    # top, bottom
                    lr = (abs(a) * i, abs(a) * (patch_len - 1 - i))    # left, right

                    # flip padding for each axis if a is negative
                    pad_width = (tb, lr, (0, 0)) if a >= 0 else (tb[::-1], lr[::-1], (0, 0))

                    # shift viewpoint image and add its values to refocused image slice
                    img_slice = np.add(img_slice, np.pad(vp_img, pad_width, 'edge'))

                    # check interrupt status
                    if self.sta.interrupt:
                        return False

                    # print status
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_exporter.py View on Github external
def export_vp_stack(self, type='png', downscale=None):
        """ write viewpoint images stitched to together in a single image """

        # print status
        self.sta.status_msg('Write viewpoint image stack', self.cfg.params[self.cfg.opt_prnt])
        self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])

        # downscale image
        downscale = True if downscale is None else downscale
        views_stacked_img = misc.img_resize(self.views_stacked_img.copy(), 1 / self._M) \
            if downscale else self.views_stacked_img.copy()

        # normalization
        p_lo = np.percentile(rgb2gry(self.central_view), 0.05)
        p_hi = np.percentile(rgb2gry(self.central_view), 99.995)
        views_stacked_img = misc.Normalizer(views_stacked_img, min=p_lo, max=p_hi).uint8_norm()

        # export all viewpoints in single image
        views_stacked_path = os.path.join(self.cfg.exp_path, 'views_stacked_img_' + str(self._M) + 'px')
        misc.save_img_file(views_stacked_img, file_path=views_stacked_path, file_type=type)

        self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])

        return True