How to use the plenopticam.misc.save_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 / lfp_reader / top_level.py View on Github external
# Lytro type decoding
        with open(self._lfp_path, mode='rb') as file:

            # LFC and raw type decoding
            obj = LfpDecoder(file, self.cfg, self.sta, lfp_path=self._lfp_path)
            obj.main()
            self._lfp_img = obj.bay_img
            self._json_dict = obj.json_dict
            del obj

            # save bayer image as file (if not already present)
            if not os.path.exists(self.fp) and not self.sta.interrupt:
                self.sta.status_msg(msg='Save raw image', opt=self.cfg.params[self.cfg.opt_prnt])
                self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])
                misc.save_img_file(misc.Normalizer(self._lfp_img).uint16_norm(), self.fp, file_type='tiff')
                self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])

        return True
github hahnec / plenopticam / plenopticam / lfp_aligner / lfp_resampler.py View on Github external
# print status
        self.sta.status_msg('Save aligned light-field', self.cfg.params[self.cfg.opt_prnt])
        self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])

        # convert to 16bit unsigned integer
        self._lfp_out = misc.Normalizer(self._lfp_out).uint16_norm()

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

        # write aligned light field as pickle file to avoid re-calculation
        with open(os.path.join(self.cfg.exp_path, 'lfp_img_align.pkl'), 'wb') as f:
            pickle.dump(self._lfp_out, f)

        if self.cfg.params[self.cfg.opt_dbug]:
            misc.save_img_file(self._lfp_out, os.path.join(self.cfg.exp_path, 'lfp_img_align.tiff'))

        self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_exporter.py View on Github external
self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])

        ptc_leng = self.cfg.params[self.cfg.ptc_leng]

        # create folder
        folderpath = os.path.join(self.cfg.exp_path, 'viewpoints_'+str(ptc_leng)+'px')
        misc.mkdir_p(folderpath)

        # normalize image array to 16-bit unsigned integer
        vp_img_arr = misc.Normalizer(self.vp_img_arr).uint16_norm()

        # export viewpoint images as image files
        for j in range(ptc_leng):
            for i in range(ptc_leng):

                misc.save_img_file(vp_img_arr[j, i], os.path.join(folderpath, str(j) + '_' + str(i)),
                                   file_type=type, tag=self.cfg.params[self.cfg.opt_dbug])

                # print status
                percentage = (((j*self._M+i+1)/self._M**2)*100)
                self.sta.progress(percentage, self.cfg.params[self.cfg.opt_prnt])

                if self.sta.interrupt:
                    return False

        return True
github hahnec / plenopticam / plenopticam / lfp_extractor / hex_corrector.py View on Github external
mask = np.divide(arr, arr.max(), out=np.zeros_like(arr), where=arr != 0)
        th = 0.1
        mask[mask < th] = 0
        mask[mask >= th] = 1

        # ignore small regions
        mask = self.retain_connected(mask, n=4)

        # generate mask
        if self.cfg.params[self.cfg.opt_dbug]:
            full_mask = np.zeros(img.shape)
            if full_mask[j::2, ...].shape[0] == mask.shape[0]:
                full_mask[j::2, ...] = mask
            else:
                full_mask[j::2, ...][:-1] = mask
            misc.save_img_file(full_mask, os.path.join(self.cfg.exp_path, 'hex_filter_mask.png'), tag=True)

        # generate image indicating which pixels were treated
        if self.cfg.params[self.cfg.opt_dbug]:
            tes = img.copy()
            for p in range(ch):
                if tes[j::2, ...].shape[0] == mask.shape[0]:
                    tes[j::2, :, p][mask[..., p] != 0] = tes.max()
                else:
                    tes[j::2, :, p][:-1][mask[..., p] != 0] = tes.max()
            tes_out = np.divide(tes, tes.max(), out=np.zeros_like(tes), where=tes != 0)
            misc.save_img_file(tes_out, os.path.join(self.cfg.exp_path, 'ident.png'), tag=True)

        idxs = np.array(mask.nonzero())
        r = 1
        valid_idx = np.where((idxs[0] > r) & (idxs[1] > r) & (img[j::2].shape[0]-idxs[0] > r) & (img.shape[1]-idxs[1] > r))[0]
        idxs_vals = list(zip(idxs[0][valid_idx], idxs[1][valid_idx], idxs[2][valid_idx]))
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_exporter.py View on Github external
def save_refo_slice(self, a, refo_img, folder_path=None, file_type=None, string=None):

        string = 'subpixel_' if self.cfg.params[self.cfg.opt_refi] and string is None else string

        if folder_path is None:
            folder_path = os.path.join(self.cfg.exp_path, 'refo_' + string + str(self._M) + 'px')
            misc.mkdir_p(folder_path)

        # write image file
        misc.save_img_file(refo_img, os.path.join(folder_path, str(a)), file_type=file_type)

        return True
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_exporter.py View on Github external
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