def __exec__(self, context, *args):
        tsi, colorcardParam = args
        image = tsi.pixels

        meanIntensity = np.mean(image)
        colorMatrix, colorConstant, colorGamma = colorcardParam
        if colorMatrix is not None and meanIntensity > self.minIntensity:
            self.imageCorrected = cd.correctColorVectorised(
                image.astype(np.float),
                colorMatrix,
                colorConstant,
                colorGamma)
            self.imageCorrected = np.clip(np.round(self.imageCorrected),
                                          0, 255)
            self.imageCorrected = self.imageCorrected.astype(np.uint8)
        else:
            # FIXME: This should be handled with an exception.
            LOG.warn('Skip color correction')
            self.imageCorrected = image
        self.image = image  # display

        # adjust intensity due to angle in field of view
        if self.fieldOfView is not None:
            imageSize = self.image.shape[1::-1]
            xp, yp = np.meshgrid(range(imageSize[0]),
                                 range(imageSize[1]))
            xp -= imageSize[0]/2
            yp -= imageSize[1]/2
            W = 2.0*np.tan(self.fieldOfView[0]/2.0/180.0*np.pi)
            H = 2.0*np.tan(self.fieldOfView[1]/2.0/180.0*np.pi)
            angleX = np.arctan(W/imageSize[0]*xp)
            angleY = np.arctan(H/imageSize[1]*yp)
            self.angles = np.sqrt(angleX**2 + angleY**2)

            # scale intensity with inverse of angle cosine
            temp0 = self.imageCorrected[:, :, 0]/np.cos(self.angles)
            temp1 = self.imageCorrected[:, :, 1]/np.cos(self.angles)
            temp2 = self.imageCorrected[:, :, 2]/np.cos(self.angles)

            # clip to range between 0 and 255 before converting to uint8
            self.imageAdjusted = np.zeros_like(self.imageCorrected)
            self.imageAdjusted[:, :, 0] = np.clip(np.round(temp0), 0, 255)
            self.imageAdjusted[:, :, 1] = np.clip(np.round(temp1), 0, 255)
            self.imageAdjusted[:, :, 2] = np.clip(np.round(temp2), 0, 255)

            tsi.pixels = self.imageAdjusted
        else:
            tsi.pixels = self.imageCorrected

        return([tsi])
    def correctColor(self):
        if self.colorcardParams == None:
            if len(self.colorcardList) > 0:
                medianSize = cd.getMedianRectSize(self.colorcardList)
                capturedColorcards = cd.rectifyRectImages(self.image, self.colorcardList, medianSize)
                self.colorcardColors, _ = cd.getColorcardColors(capturedColorcards[0], GridSize = [6, 4])
                self.colorcardParams = cd.estimateColorParameters(cd.CameraTrax_24ColorCard, self.colorcardColors)
            else:
                self.status.append('Need to select a color card first.')
                return

        colorMatrix, colorConstant, colorGamma = self.colorcardParams
        self.imageCorrected = cd.correctColorVectorised(self.image.astype(np.float), colorMatrix, colorConstant, colorGamma)
        self.imageCorrected[np.where(self.imageCorrected < 0)] = 0
        self.imageCorrected[np.where(self.imageCorrected > 255)] = 255
        self.imageCorrected = self.imageCorrected.astype(np.uint8)
        self.updateFigure(self.imageCorrected)
Esempio n. 3
0
    def __call__(self, context, *args):
        LOG.info(self.mess)
        tsi, colorcardParam = args
        image = tsi.pixels

        meanIntensity = np.mean(image)
        colorMatrix, colorConstant, colorGamma = colorcardParam
        if colorMatrix is not None and meanIntensity > self.minIntensity:
            self.imageCorrected = cd.correctColorVectorised(
                image.astype(np.float),
                colorMatrix,
                colorConstant,
                colorGamma)
            self.imageCorrected[np.where(self.imageCorrected < 0)] = 0
            self.imageCorrected[np.where(self.imageCorrected > 255)] = 255
            self.imageCorrected = self.imageCorrected.astype(np.uint8)
        else:
            # FIXME: This should be handled with an exception.
            LOG.warn('Skip color correction')
            self.imageCorrected = image
        self.image = image  # display

        tsi.pixels = self.imageCorrected
        return([tsi])