def show(self):
        plt.figure()
        plt.subplot(211)
        plt.imshow(cd.rotateImage(self.image))
        plt.title('Original image')

        plt.subplot(212)
        plt.imshow(self.imageUndistorted)
        plt.title('Undistorted image')
        plt.show()
    def __call__(self, context, *args):
        LOG.info(self.mess)
        tsi = args[0]
        self.image = tsi.pixels
        if self.UndistMapX is not None and self.UndistMapY is not None:
            self.imageUndistorted = cv2.remap(self.image.astype(np.uint8),
                                              self.UndistMapX, self.UndistMapY,
                                              cv2.INTER_CUBIC)
        else:
            self.imageUndistorted = self.image

        tsi.pixels = cd.rotateImage(self.imageUndistorted, self.rotationAngle)
        return [tsi]
    def __exec__(self, context, *args):
        tsi = args[0]
        self.image = tsi.pixels

        if self.image is None:
            raise PCExBadImage(tsi.path)

        if self.UndistMapX is not None and self.UndistMapY is not None:
            self.imageUndistorted = cv2.remap(self.image.astype(np.uint8),
                                              self.UndistMapX, self.UndistMapY,
                                              cv2.INTER_CUBIC)
        else:
            self.imageUndistorted = self.image

        tsi.pixels = cd.rotateImage(self.imageUndistorted,
                                    self.rotationAngle)
        return [tsi]
    def loadImage(self):
        ''' load and show an image'''
        if self.tsImages != None:
            try:
                tsImage = self.tsImages.next()
                if tsImage.pixels == np.array([]):
                    self.status.append('Missing image.')
            except:
                tsImage.pixels == np.array([])
                self.status.append('There is no more images.')

            if tsImage.pixels == np.array([]):
                self.image = None
                self.updateFigure()
                return
            self.image = tsImage.pixels
            fname = tsImage.path
        else:
            fname = QtGui.QFileDialog.getOpenFileName(self, 'Open image', '/mnt/phenocam/a_data/TimeStreams/Borevitz/BVZ0036/BVZ0036-GC02L-C01~fullres-orig/2014/2014_06/2014_06_24/2014_06_24_08/')
            app.processEvents()
            if len(fname) == 0:
                return
            self.image = cv2.imread(str(fname))[:,:,::-1]
        self.status.append('Loaded image from ' + str(fname))

        # reset all outputs
#        self.colorcardList = []
#        self.trayList = []
#        self.potList = []
        self.isDistortionCorrected = False

        if self.rotationAngle != None:
            self.image = cd.rotateImage(self.image, self.rotationAngle + self.smaleRotationAngle)

        # Undistort image if mapping available
        if not self.isDistortionCorrected and self.UndistMapX != None and self.UndistMapY != None:
            self.image = cv2.remap(self.image.astype(np.uint8), self.UndistMapX, self.UndistMapY, cv2.INTER_CUBIC)
            self.isDistortionCorrected = True

        self.updateFigure()
 def applySmallRotation(self):
     if self.image != None:
         self.image = cd.rotateImage(self.image, self.smaleRotationAngle)
         self.updateFigure()
         self.status.append('Apply small angle rotation')
 def rotateSmallAngle(self, value):
     self.smaleRotationAngle = float(value)/4.0
     if self.image != None:
         self.rotatedImage = cd.rotateImage(self.image, self.smaleRotationAngle)
         self.updateFigure(self.rotatedImage)
         self.status.append('Rot. angle = %f deg' %(self.rotationAngle + self.smaleRotationAngle))