How to use the plenopticam.misc.Normalizer 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 / brisque_analysis_flip.py View on Github external
# 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))

        score_series.append(scores)

    # plot
    plt.style.use('seaborn-white')
    fig = plt.figure()
    softx__width = 5.39749
    a = softx__width*4
    fig.set_size_inches(w=softx__width, h=a)
    width = .3#.25

    for i, scores in enumerate(score_series):
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_exporter.py View on Github external
def export_thumbnail(self, type='tiff'):

        thumb = misc.Normalizer(self.central_view.copy()).type_norm()

        # export central viewpoint as thumbnail image
        fp = os.path.join(self.cfg.exp_path, 'thumbnail')
        misc.save_img_file(thumb, file_path=fp, file_type=type, tag=self.cfg.params[self.cfg.opt_dbug])

        return True
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_extractor / lfp_contrast.py View on Github external
def auto_hist_align(img, ref_img, opt=None):

        if opt:
            p_lo, p_hi = (0.005, 99.9)#(0.001, 99.999)
            min_perc = np.percentile(rgb2gry(ref_img), p_lo)
            max_perc = np.percentile(ref_img, p_hi)
        else:
            p_lo, p_hi = (0.5, 99.9)
            min_perc = np.percentile(ref_img, p_lo)
            max_perc = np.percentile(ref_img, p_hi)

        img = misc.Normalizer(img, min=min_perc, max=max_perc).type_norm()

        return img
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_contrast.py View on Github external
def con_bal(self):

        # find extrema from reference image
        self.ref_img = yuv_conv(self.central_view)[..., 0]
        max = self.ref_img.max()
        min = self.ref_img.min()

        # convert to yuv space
        self.proc_vp_arr(yuv_conv, msg='Convert to YUV')

        # boost luminance channel
        self.sta.status_msg(msg='Contrast balance', opt=self.cfg.params[self.cfg.opt_prnt])
        self._vp_img_arr[..., 0] = misc.Normalizer(self._vp_img_arr[..., 0]).type_norm(max=max, min=min)
        self.sta.progress(100, opt=self.cfg.params[self.cfg.opt_prnt])

        # convert to rgb space
        self.proc_vp_arr(yuv_conv, inverse=True, msg='Convert to RGB')

        return True
github hahnec / plenopticam / plenopticam / lfp_refocuser / lfp_scheimpflug.py View on Github external
for y in range(m):
            for x in range(n):
                scheimpflug_img[y, x] = self.refo_stack[a_map[y, x]][y, x]

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

                # print status
                percentage = (((y*n+x+1)/(m*n))*100)
                self.sta.progress(percentage, self.cfg.params[self.cfg.opt_prnt])

        # write image file to hard drive
        a_ran = self.cfg.params[self.cfg.ran_refo]
        fn = 'scheimpflug_' + str(a_ran[0]) + '_' + str(a_ran[-1]) + '_' + self.cfg.params[self.cfg.opt_pflu] + '.png'
        misc.save_img_file(misc.Normalizer(scheimpflug_img).uint16_norm(), os.path.join(self.fp, fn))

        return True
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_contrast.py View on Github external
def thresh_hist_stretch(self, th=2e-10, bins=2**16-1):

        h = np.histogram(self.central_view, bins=bins)
        hn = h[0] / h[0].sum()
        x_vals = np.where(hn / len(hn) > th)[0] / bins

        hs = np.diff(h[0][::128] / h[0][::128].sum())
        s_vals = np.where(hs > 1.5e-4)[0] / (bins / 128)

        #img = misc.Normalizer(self.central_view.copy(), min=x_vals[1], max=self.central_view.max()).type_norm()
        self.proc_vp_arr(misc.Normalizer().type_norm, msg='Histogram crop', min=x_vals[1], max=1)

        return True
github hahnec / plenopticam / plenopticam / lfp_extractor / lfp_exporter.py View on Github external
def export_viewpoints(self, type='tiff'):

        # print status
        self.sta.status_msg('Write viewpoint images', self.cfg.params[self.cfg.opt_prnt])
        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 / lfp_contrast.py View on Github external
self.sta.progress(0, opt=self.cfg.params[self.cfg.opt_prnt])

        ch_num = self.vp_img_arr.shape[-1] if len(self.vp_img_arr.shape) > 4 else 3
        for i in range(ch_num):
            if method is None:

                # channel selection
                ref_ch = self.ref_img[..., i]
                img_ch = self.vp_img_arr[..., i]

                # define level limits
                min = np.percentile(ref_ch, self.p_lo*100)
                max = np.percentile(ref_ch, self.p_hi*100)

                # normalization of color channel
                self.vp_img_arr[..., i] = misc.Normalizer(img_ch, min=min, max=max).uint16_norm()

            else:
                # brightness and contrast method
                self.set_stretch(ref_ch=self.ref_img[..., i])
                self.apply_stretch(ch=i)

            # status update
            if msg_opt:
                self.sta.progress((i+1)/ch_num*100, opt=self.cfg.params[self.cfg.opt_prnt])

        return True
github hahnec / plenopticam / plenopticam / lfp_refocuser / lfp_scheimpflug.py View on Github external
# consider negative shift
                negative_a = int((patch_len - 1) * abs(a)) if a < 0 else 0

                # centralize column
                column_shift = int((a_x.max()-a)*(patch_len-1)/2)

                # put interpolated vector to refocusing plane
                newY = int(y + np.mod(y, patch_len) * (a - 1) + negative_a) + column_shift
                ver_refo[newY:newY + patch_len, :, :] = ver_refo[newY:newY + patch_len, :, :] + frac_vec

            # print progress status
            self.sta.progress(((x+1)/new_n+.5)*100, self.cfg.params[self.cfg.opt_prnt])

        # write image file to hard drive
        img = misc.Normalizer(ver_refo).uint16_norm()
        misc.save_img_file(img, os.path.join(self.fp, 'scheimpflug_' + str(patch_len) + 'px.tiff'))

        return True