How to use the plenopticam.misc.safe_get 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_calibrator / auto_find_cali.py View on Github external
""" decode raw data to obtain bayer image and settings data """

        # skip if calibrated json file already exists, otherwise perform centroid calibration
        if self._raw_data:

            # decode raw data
            obj = LfpDecoder(self._raw_data, self.cfg, self.sta)
            obj.decode_raw()
            self._wht_bay = obj.bay_img
            del obj

            # balance Bayer channels in white image
            try:
                frame_arr = safe_get(self._wht_json, 'master', 'picture', 'frameArray')[0]
                self.cfg.lfpimg['ccm_wht'] = safe_get(frame_arr, 'frame', 'metadata', 'image', 'color', 'ccmRgbToSrgbArray')
                awb = safe_get(frame_arr, 'frame', 'metadata', 'devices', 'sensor', 'normalizedResponses')[0]
                gains = [1./awb['b'], 1./awb['r'], 1./awb['gr'], 1./awb['gb']]
                self.cfg.lfpimg['awb_wht'] = gains
            except ValueError:
                gains = [1/0.74476742744445801, 1/0.76306647062301636, 1, 1]

            # apply white balance gains to calibration file
            cfa_obj = CfaProcessor(bay_img=self._wht_bay, cfg=self.cfg, sta=self.sta)
            cfa_obj.set_gains(gains)
            self._wht_bay = cfa_obj.apply_awb()
            del cfa_obj

        return True
github hahnec / plenopticam / plenopticam / lfp_reader / lfp_decoder.py View on Github external
# filter camera serial and model
        serial = safe_get(json_dict, 'camera', 'serialNumber')
        cam_model = serial if serial else safe_get(json_dict, 'camera', 'model')

        # set decode paramaters considering camera model
        if cam_model.startswith(('A', 'F')):    # 1st generation Lytro

            # read bit packing
            settings['bit'] = safe_get(json_dict, "image", "rawDetails", "pixelPacking", "bitsPerPixel")
            if not settings['bit'] == 12:
                raise AssertionError('Unrecognized bit packing format')

            # get Bayer pattern, Automatic White Balance (AWB) gains and Color Correction Matrix (CCM)
            settings['bay'] = 'BGGR'
            settings['awb'] = [safe_get(json_dict, 'image', 'color', 'whiteBalanceGain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccmRgbToSrgbArray')
            settings['gam'] = safe_get(json_dict, 'image', 'color', 'gamma')

        elif cam_model.startswith(('B', 'I')):  # 2nd generation Lytro

            # read bit packing
            settings['bit'] = safe_get(json_dict, "image", "pixelPacking", "bitsPerPixel")
            if not settings['bit'] == 10:
                raise AssertionError('Unrecognized bit packing format')

            # get Bayer pattern, Automatic White Balance (AWB) gains and Color Correction Matrix (CCM)
            settings['bay'] = 'GRBG'
            settings['awb'] = [safe_get(json_dict, 'algorithms', 'awb', 'computed', 'gain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccm')
            settings['gam'] = safe_get(json_dict, 'master', 'picture', 'frameArray', 0, 'frame', 'metadata', 'image',
                                       'color', 'gamma')
            settings['exp'] = safe_get(json_dict, "image", "modulationExposureBias")
github hahnec / plenopticam / plenopticam / lfp_reader / lfp_decoder.py View on Github external
def filter_lfp_json(json_dict, settings=None):
        ''' filter LFP metadata settings '''

        # variable init
        settings = {} if settings is None else settings
        channels = ['b', 'r', 'gb', 'gr']

        # filter camera serial and model
        serial = safe_get(json_dict, 'camera', 'serialNumber')
        cam_model = serial if serial else safe_get(json_dict, 'camera', 'model')

        # set decode paramaters considering camera model
        if cam_model.startswith(('A', 'F')):    # 1st generation Lytro

            # read bit packing
            settings['bit'] = safe_get(json_dict, "image", "rawDetails", "pixelPacking", "bitsPerPixel")
            if not settings['bit'] == 12:
                raise AssertionError('Unrecognized bit packing format')

            # get Bayer pattern, Automatic White Balance (AWB) gains and Color Correction Matrix (CCM)
            settings['bay'] = 'BGGR'
            settings['awb'] = [safe_get(json_dict, 'image', 'color', 'whiteBalanceGain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccmRgbToSrgbArray')
            settings['gam'] = safe_get(json_dict, 'image', 'color', 'gamma')

        elif cam_model.startswith(('B', 'I')):  # 2nd generation Lytro

            # read bit packing
            settings['bit'] = safe_get(json_dict, "image", "pixelPacking", "bitsPerPixel")
            if not settings['bit'] == 10:
                raise AssertionError('Unrecognized bit packing format')
github hahnec / plenopticam / plenopticam / lfp_calibrator / auto_find_cali.py View on Github external
def main(self):

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

        # auto calibration can only be used if calibration source path is either directory or tar archive
        if isdir(self._path) or self._path.lower().endswith('.tar'):

            # read JSON file from selected *.lfp image
            self._lfp_json = self.cfg.load_json(self.cfg.params[self.cfg.lfp_path])

            # extract serial number to support search
            self._serial = safe_get(self._lfp_json, 'camera', 'serialNumber')
            self._cam_model = self._serial if self._serial else safe_get(self._lfp_json, 'camera', 'model')

            # extract calibration reference data
            if self._cam_model.startswith(('A', 'F')):
                frames = safe_get(self._lfp_json, 'picture', 'derivationArray') #'frameArray')  #
                self._georef = frames[0]    #safe_get(frames[0], 'frame', 'imageRef') if frames else ''   #

            elif self._cam_model.startswith(('B', 'I')):
                frames = safe_get(self._lfp_json, 'frames')
                self._georef = safe_get(frames[0], 'frame', 'geometryCorrectionRef') if frames else ''

            # print status
            if not self._serial and isdir(self._path):
                self.sta.status_msg('No serial number found in JSON file. Provide calibration file instead of folder',
                                    self._opt_prnt)
                self.sta.error = True
github hahnec / plenopticam / plenopticam / lfp_reader / lfp_decoder.py View on Github external
# decode lfp file
        sections = self.read_buffer(self.file)

        # retrieve JSON data
        self._json_dict = self.read_json(sections)

        # JSON file export
        dp = os.path.splitext(self._lfp_path)[0]
        self.cfg.save_json(os.path.join(dp, os.path.basename(dp) + '.json'), json_dict=self.json_dict)

        # validate camera format support
        if not self.valid_cam_type:
            return False

        # decompose JSON data
        self._shape = [safe_get(self._json_dict, 'image', 'width'), safe_get(self._json_dict, 'image', 'height')]

        # filter LFP metadata settings
        self.cfg.lfpimg = self.filter_lfp_json(self._json_dict)

        # compose bayer image from lfp file
        sec_idx = self.get_idx(sections, int(self._shape[0] * self._shape[1] * self.cfg.lfpimg['bit'] / 8))[0]
        self._img_buf = list(sections[sec_idx])
        self.comp_bayer()

        return True
github hahnec / plenopticam / plenopticam / lfp_calibrator / auto_find_cali.py View on Github external
def _raw2img(self):
        """ decode raw data to obtain bayer image and settings data """

        # skip if calibrated json file already exists, otherwise perform centroid calibration
        if self._raw_data:

            # decode raw data
            obj = LfpDecoder(self._raw_data, self.cfg, self.sta)
            obj.decode_raw()
            self._wht_bay = obj.bay_img
            del obj

            # balance Bayer channels in white image
            try:
                frame_arr = safe_get(self._wht_json, 'master', 'picture', 'frameArray')[0]
                self.cfg.lfpimg['ccm_wht'] = safe_get(frame_arr, 'frame', 'metadata', 'image', 'color', 'ccmRgbToSrgbArray')
                awb = safe_get(frame_arr, 'frame', 'metadata', 'devices', 'sensor', 'normalizedResponses')[0]
                gains = [1./awb['b'], 1./awb['r'], 1./awb['gr'], 1./awb['gb']]
                self.cfg.lfpimg['awb_wht'] = gains
            except ValueError:
                gains = [1/0.74476742744445801, 1/0.76306647062301636, 1, 1]

            # apply white balance gains to calibration file
            cfa_obj = CfaProcessor(bay_img=self._wht_bay, cfg=self.cfg, sta=self.sta)
            cfa_obj.set_gains(gains)
            self._wht_bay = cfa_obj.apply_awb()
            del cfa_obj

        return True
github hahnec / plenopticam / plenopticam / lfp_reader / lfp_decoder.py View on Github external
settings['awb'] = [safe_get(json_dict, 'image', 'color', 'whiteBalanceGain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccmRgbToSrgbArray')
            settings['gam'] = safe_get(json_dict, 'image', 'color', 'gamma')

        elif cam_model.startswith(('B', 'I')):  # 2nd generation Lytro

            # read bit packing
            settings['bit'] = safe_get(json_dict, "image", "pixelPacking", "bitsPerPixel")
            if not settings['bit'] == 10:
                raise AssertionError('Unrecognized bit packing format')

            # get Bayer pattern, Automatic White Balance (AWB) gains and Color Correction Matrix (CCM)
            settings['bay'] = 'GRBG'
            settings['awb'] = [safe_get(json_dict, 'algorithms', 'awb', 'computed', 'gain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccm')
            settings['gam'] = safe_get(json_dict, 'master', 'picture', 'frameArray', 0, 'frame', 'metadata', 'image',
                                       'color', 'gamma')
            settings['exp'] = safe_get(json_dict, "image", "modulationExposureBias")

        return settings
github hahnec / plenopticam / plenopticam / lfp_reader / lfp_decoder.py View on Github external
settings['bay'] = 'BGGR'
            settings['awb'] = [safe_get(json_dict, 'image', 'color', 'whiteBalanceGain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccmRgbToSrgbArray')
            settings['gam'] = safe_get(json_dict, 'image', 'color', 'gamma')

        elif cam_model.startswith(('B', 'I')):  # 2nd generation Lytro

            # read bit packing
            settings['bit'] = safe_get(json_dict, "image", "pixelPacking", "bitsPerPixel")
            if not settings['bit'] == 10:
                raise AssertionError('Unrecognized bit packing format')

            # get Bayer pattern, Automatic White Balance (AWB) gains and Color Correction Matrix (CCM)
            settings['bay'] = 'GRBG'
            settings['awb'] = [safe_get(json_dict, 'algorithms', 'awb', 'computed', 'gain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccm')
            settings['gam'] = safe_get(json_dict, 'master', 'picture', 'frameArray', 0, 'frame', 'metadata', 'image',
                                       'color', 'gamma')
            settings['exp'] = safe_get(json_dict, "image", "modulationExposureBias")

        return settings
github hahnec / plenopticam / plenopticam / lfp_reader / lfp_decoder.py View on Github external
# get Bayer pattern, Automatic White Balance (AWB) gains and Color Correction Matrix (CCM)
            settings['bay'] = 'BGGR'
            settings['awb'] = [safe_get(json_dict, 'image', 'color', 'whiteBalanceGain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccmRgbToSrgbArray')
            settings['gam'] = safe_get(json_dict, 'image', 'color', 'gamma')

        elif cam_model.startswith(('B', 'I')):  # 2nd generation Lytro

            # read bit packing
            settings['bit'] = safe_get(json_dict, "image", "pixelPacking", "bitsPerPixel")
            if not settings['bit'] == 10:
                raise AssertionError('Unrecognized bit packing format')

            # get Bayer pattern, Automatic White Balance (AWB) gains and Color Correction Matrix (CCM)
            settings['bay'] = 'GRBG'
            settings['awb'] = [safe_get(json_dict, 'algorithms', 'awb', 'computed', 'gain', key) for key in channels]
            settings['ccm'] = safe_get(json_dict, 'image', 'color', 'ccm')
            settings['gam'] = safe_get(json_dict, 'master', 'picture', 'frameArray', 0, 'frame', 'metadata', 'image',
                                       'color', 'gamma')
            settings['exp'] = safe_get(json_dict, "image", "modulationExposureBias")

        return settings