Пример #1
0
    def main(self):

        # compute LoG to remove high frequency noise and emphasize peaks
        self.compute_log()

        # find micro image centers
        self.compute_centroids()

        from plenopticam.lfp_calibrator.centroid_drawer import CentroidDrawer
        CentroidDrawer(
            self._peak_img, self._centroids,
            self._cfg).write_centroids_img(fn='wht_img+mics_nms.png')

        if self._method is not None:
            # refine centroids with sub-pixel precision using provided method
            ref_obj = CentroidRefiner(self._peak_img,
                                      self._centroids,
                                      self._cfg,
                                      self._sta,
                                      self._M,
                                      method=self._method)
            ref_obj.main()
            self._centroids = ref_obj.centroids_refined
            del ref_obj

            from plenopticam.lfp_calibrator.centroid_drawer import CentroidDrawer
            CentroidDrawer(
                self._img, self._centroids,
                self._cfg).write_centroids_img(fn='wht_img+mics_refi.png')

        return True
Пример #2
0
    def main(self):

        # ensure white image is monochromatic
        self._wht_img = rgb2gray(
            self._wht_img) if len(self._wht_img.shape) is 3 else self._wht_img

        # estimate micro image diameter
        obj = PitchEstimator(self._wht_img, self.cfg, self.sta)
        obj.main()
        self._M = obj.M if not self._M else self._M
        del obj

        # compute all centroids of micro images
        obj = CentroidExtractor(self._wht_img, self.cfg, self.sta, self._M)
        obj.main()
        centroids = obj.centroids
        del obj

        # write micro image center image to hard drive if debug option is set
        if not self.sta.interrupt:
            CentroidDrawer(
                self._wht_img, centroids,
                self.cfg).write_centroids_img(fn='wht_img+mics_unsorted.png')

        # reorder MICs and assign indices based on the detected MLA pattern
        obj = CentroidSorter(centroids, self.cfg, self.sta)
        obj.main()
        mic_list, pattern, pitch = obj.mic_list, obj.pattern, obj.pitch
        del obj

        # save calibration metadata
        self.sta.status_msg('Save calibration data',
                            opt=self.cfg.params[self.cfg.opt_dbug])
        self.sta.progress(None, opt=self.cfg.params[self.cfg.opt_dbug])
        try:
            self.cfg.save_cal_data(mic_list=mic_list,
                                   pat_type=pattern,
                                   ptc_mean=pitch)
        except:
            self.sta.status_msg('Could not save calibration data',
                                opt=self.cfg.params[self.cfg.opt_dbug])

        # write image to hard drive if debug option is set
        if not self.sta.interrupt:
            CentroidDrawer(
                self._wht_img, mic_list,
                self.cfg).write_centroids_img(fn='wht_img+mics_sorted.png')

        # print status
        self.sta.status_msg('Finished calibration', opt=True)
        self.sta.progress(100, opt=True)

        return True
Пример #3
0
    def main(self):

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

        # status message handling
        self.sta.status_msg('Refine micro image centers',
                            self.cfg.params[self.cfg.opt_prnt])
        self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])

        fun = self._peak_centroid if self._method == 'peak' else self._area_centroid

        # coordinate and image downsampling preparation
        self._centroids = [(x // DR, y // DR) for x, y in self._centroids
                           ] if DR > 1 else self._centroids
        img_scale = self._img[::DR, ::DR]

        r = self._M // 2 // DR
        self._centroids_refined = []

        # iterate through all centroids for refinement procedure
        for i, m in enumerate(self._centroids):

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

            # compute refined coordinates based on given method
            fun(
                img_scale[int(m[0]) - r:int(m[0]) + r + 1,
                          int(m[1]) - r:int(m[1]) + r + 1], m)
            self._centroids_refined.append(self._get_coords())

            # print status
            self.sta.progress((i + 1) / len(self._centroids) * 100,
                              self.cfg.params[self.cfg.opt_prnt])

        # coordinate upsampling to compensate for downsampling
        self._centroids_refined = [
            (x * DR, y * DR) for x, y in self._centroids_refined
        ] if DR > 1 else self._centroids_refined

        # remove centroids at image boundaries
        self.exclude_marginal_centroids()

        # write centroids image to hard drive (if option set)
        if self.cfg.params[self.cfg.opt_dbug] and not self.sta.interrupt:
            draw_obj = CentroidDrawer(self._img, self._centroids, self.cfg)
            draw_obj.write_centroids_img(fn='wht_img+mics_refi.png')
            del draw_obj

        return True
Пример #4
0
    def main(self):

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

        # compute LoG to remove high frequency noise and emphasize peaks
        self.compute_log()

        # find micro image centers
        self.compute_centroids()

        # write centroids image to hard drive (if option set)
        if self.cfg.params[self.cfg.opt_dbug] and not self.sta.interrupt:
            draw_obj = CentroidDrawer(self._peak_img, self._centroids,
                                      self.cfg)
            draw_obj.write_centroids_img(fn='wht_img+mics_nms.png')
            del draw_obj

        return True
Пример #5
0
    def main(self):

        # determine rotation angle (radians) of micro image centers (skip if angle already set)
        self._estimate_rad() if self._rad is None else None

        # rotate image
        self._rotate_img()

        # rotate centroids
        self._rotate_centroids()

        # write plot img to hard drive (debug only)
        CentroidDrawer(self._lfp_img, self._centroids, self.cfg).write_centroids_img(fn='lfp_rotated.png')

        return True
Пример #6
0
    def main(self):

        # determine rotation angle (radians) of micro image centers (skip if angle already set)
        self._estimate_rad() if self._rad is None else None

        # rotate image
        self._rotate_img()

        # rotate centroids
        self._rotate_centroids()

        # write plot img to hard drive (debug only)
        if self.cfg.params[self.cfg.opt_dbug] and not self.sta.interrupt:
            self.sta.status_msg('Save rotated image (debug mode)')
            self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])
            CentroidDrawer(self._lfp_img, self._centroids,
                           self.cfg).write_centroids_img(fn='lfp_rotated.png')
            self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])

        return True
Пример #7
0
    def main(self):

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

        # compute LoG to remove high frequency noise and emphasize peaks
        self.compute_log()

        # find micro image centers
        self.compute_centroids()

        if self.cfg.params[self.cfg.opt_dbug] and not self.sta.interrupt:
            draw_obj = CentroidDrawer(self._peak_img, self._centroids,
                                      self.cfg)
            draw_obj.write_centroids_img(fn='wht_img+mics_nms.png')
            del draw_obj

        if self._method is not None:
            # refine centroids with sub-pixel precision using provided method
            ref_obj = CentroidRefiner(self._peak_img,
                                      self._centroids,
                                      self.cfg,
                                      self.sta,
                                      self._M,
                                      method=self._method)
            ref_obj.main()
            self._centroids = ref_obj.centroids_refined
            del ref_obj

            if self.cfg.params[self.cfg.opt_dbug] and not self.sta.interrupt:
                draw_obj = CentroidDrawer(self._img, self._centroids, self.cfg)
                draw_obj.write_centroids_img(fn='wht_img+mics_refi.png')
                del draw_obj

        return True
Пример #8
0
    def main(self):

        if self._wht_img is None:
            self.sta.status_msg(msg='White image file not present',
                                opt=self.cfg.params[self.cfg.opt_prnt])
            self.sta.error = True

        # convert Bayer to RGB representation
        if len(self._wht_img.shape) == 2 and 'bay' in self.cfg.lfpimg:
            # perform color filter array management and obtain rgb image
            cfa_obj = CfaProcessor(bay_img=self._wht_img,
                                   cfg=self.cfg,
                                   sta=self.sta)
            cfa_obj.bay2rgb()
            self._wht_img = cfa_obj.rgb_img
            del cfa_obj

        # ensure white image is monochromatic
        if len(self._wht_img.shape) == 3:
            self._wht_img = rgb2gry(self._wht_img)[
                ..., 0] if self._wht_img.shape[-1] == 3 else self._wht_img

        # estimate micro image diameter
        obj = PitchEstimator(self._wht_img, self.cfg, self.sta)
        obj.main()
        self._M = obj.M if not self._M else self._M
        del obj

        # compute all centroids of micro images
        obj = CentroidExtractor(self._wht_img,
                                self.cfg,
                                self.sta,
                                self._M,
                                method='area')
        obj.main()
        centroids = obj.centroids
        del obj

        # write micro image center image to hard drive if debug option is set
        if self.cfg.params[self.cfg.opt_dbug]:
            draw_obj = CentroidDrawer(self._wht_img, centroids, self.cfg,
                                      self.sta)
            draw_obj.write_centroids_img(fn='wht_img+mics_unsorted.png')
            del draw_obj

        # reorder MICs and assign indices based on the detected MLA pattern
        obj = CentroidSorter(centroids, self.cfg, self.sta)
        obj.main()
        mic_list, pattern, pitch = obj.mic_list, obj.pattern, obj.pitch
        del obj

        # fit grid of MICs using least-squares method to obtain accurate MICs from line intersections
        if not self.sta.interrupt and None:
            from plenopticam.lfp_calibrator import GridFitter
            self.cfg.calibs[self.cfg.pat_type] = pattern
            obj = GridFitter(coords_list=mic_list, cfg=self.cfg, sta=self.sta)
            obj.main()
            mic_list = obj.grid_fit
            del obj

        # save calibration metadata
        self.sta.status_msg('Save calibration data',
                            opt=self.cfg.params[self.cfg.opt_prnt])
        self.sta.progress(None, opt=self.cfg.params[self.cfg.opt_prnt])
        try:
            self.cfg.save_cal_data(mic_list=mic_list,
                                   pat_type=pattern,
                                   ptc_mean=pitch)
            self.sta.progress(100, opt=self.cfg.params[self.cfg.opt_prnt])
        except PermissionError:
            self.sta.status_msg('Could not save calibration data',
                                opt=self.cfg.params[self.cfg.opt_prnt])

        # write image to hard drive (only if debug option is set)
        if self.cfg.params[self.cfg.opt_dbug]:
            draw_obj = CentroidDrawer(self._wht_img, mic_list, self.cfg,
                                      self.sta)
            draw_obj.write_centroids_img(fn='wht_img+mics_sorted.png')
            del draw_obj

        return True