Beispiel #1
0
    def capture_background(self):
        """ Capture an image into a 2d-array using current exposure settings"""

        if self.col == 'Interpolated':
            self.interpolate = True
        else:
            self.interpolate = False

        st = time.time()
        BayerArray = camarray.PiBayerArray(self)
        self.capture(BayerArray, 'jpeg', bayer=True)
        # bayer ordering
        ((ry, rx), (gy, gx), (Gy, Gx),
         (by, bx)) = BayerArray.BAYER_OFFSETS[BayerArray._header.bayer_order]

        et1 = time.time() - st
        print('elapsed time (capture):', et1)

        if self.interpolate:
            ## Use full resolution by interpolating the bayer data back to the full sensor resolution

            ## demosaic - postprocess ccd data back to full resolution rgb array
            self.background = BayerArray.demosaic()
            et2 = time.time() - st
            print('elapsed time (demosaic):', et2)

            ##red pixels only:
            self.background = np.asarray(self.background[:, :, 0], dtype=int)
        else:
            ## Lose a factor of 2 in resolution, but without interpolating
            ## Use only 1 color of pixel in the bayer pattern - much faster than demosaic!

            ## red pixels only:
            if self.col == 'Red':
                print(BayerArray.array)
                self.background = np.asarray(BayerArray.array[ry::2, rx::2, 0],
                                             dtype=int)

            elif self.col == 'Green':
                ## green pixels:
                self.background = np.asarray(BayerArray.array[gy::2, gx::2, 1],
                                             dtype=int)

            else:
                ## blue pixels:
                self.background = np.asarray(BayerArray.array[by::2, bx::2, 2],
                                             dtype=int)
Beispiel #2
0
    def capture_image(self):
        """ Capture an image into a 2d-array using current exposure settings"""

        if self.col == 'Interpolated':
            self.interpolate = True
        else:
            self.interpolate = False

        if self.auto_exp == 'auto':
            self.shutter_speed = self.autoexpose()

        st = time.time()
        BayerArray = camarray.PiBayerArray(self)
        self.capture(BayerArray, 'jpeg', bayer=True)
        # bayer ordering
        ((ry, rx), (gy, gx), (Gy, Gx),
         (by, bx)) = BayerArray.BAYER_OFFSETS[BayerArray._header.bayer_order]

        et1 = time.time() - st
        print('elapsed time (capture):', et1)

        #print BayerArray.array.shape
        #self.image = BayerArray.array ## full BGGR bayer mosaic array

        if self.interpolate:
            ## Use full resolution by interpolating the bayer data back to the full sensor resolution

            ##demosaic - postprocess ccd data back to full resolution rgb array
            self.image = np.asarray(BayerArray.demosaic(), dtype=int)
            et2 = time.time() - st
            print('elapsed time (demosaic):', et2)

            ##red pixel values:
            self.image = self.image[:, :, 0]
        else:
            ## Lose a factor of 2 in resolution, but without interpolating - i.e. use only 1 color of pixel

            # red pixels:
            ## red pixels only:
            if self.col == 'Red':
                print(BayerArray.array)
                self.image = np.asarray(BayerArray.array[ry::2, rx::2, 0],
                                        dtype=int)

            elif self.col == 'Green':
                ## green pixels:
                self.image = np.asarray(BayerArray.array[gy::2, gx::2, 1],
                                        dtype=int)

            else:
                ## blue pixels:
                self.image = np.asarray(BayerArray.array[by::2, bx::2, 2],
                                        dtype=int)
                # dtype=int >> converts to signed integers - otherwise background subtraction can fail

        ## apply crops for region of interest here
        h, w = self.image.shape
        self.roi_frac = [int(self.roi[0]/self.ccd_xsize),int(self.roi[1]/self.ccd_xsize),\
            1-int(self.roi[2]/self.ccd_ysize),1-int(self.roi[3]/self.ccd_ysize)]

        self.cropped_image = self.image[h * self.roi_frac[3]:h *
                                        self.roi_frac[2], w *
                                        self.roi_frac[0]:w * self.roi_frac[1]]
        if self.background is not None:
            cropped_bg = self.background[h * self.roi_frac[3]:h *
                                         self.roi_frac[2], w *
                                         self.roi_frac[0]:w * self.roi_frac[1]]

        # remove dark frame
        if self.bg_subtract:
            if self.background is None:
                print('\t !! WARNING :: No dark frame image to subtract ')
            else:
                self.image = self.image - self.background
                self.cropped_image = self.cropped_image - cropped_bg

        #print self.roi_frac
        #print 'Cropped shape:', cropped_image.shape
        ch, cw = self.cropped_image.shape

        # only fit to cropped part of the image
        self.imageX = self.cropped_image.sum(axis=0).astype(np.float) / ch
        self.imageY = self.cropped_image.sum(axis=1).astype(np.float) / cw

        # Approximate position - should use neareset integer to Ntimes pixel pitch
        self.Xs = np.linspace(self.roi[0], self.roi[1], cw)
        self.Ys = np.linspace(self.roi[3], self.roi[2], ch)

        et2 = time.time() - st
        print('elapsed time (capture + processing):', et2)
        self.et2 = et2