Ejemplo n.º 1
0
    def insertLayer(self, index, name=None, data=None):
        '''
        insert a new image as layer
        ...add new / override existing layer
        ...show dialog when data.shape != self.image.shape
        '''
        if data is not None:
            try:
                self.image = np.insert(self.image, index, data, axis=0)

            except IndexError:
                index = -1
                self.image = np.insert(self.image, index, data, axis=0)
                
            except (ValueError, MemoryError):
                if index == 0 and len(self.image) == 1:
                    #replace, if only has one layer
                    self.image = np.expand_dims(data, axis=0)
                else:
                    if type(data) == list:
                        data = data[0]

                    s1 = self.image[0].shape
                    s2 = data.shape
                    #LAYER COLOR IS DIFFERENT:
                    c1 = isColor(self.image[0])
                    c2 = isColor(data)
                    if c1 and not c2:
                        data = toColor(data)
                        s2 = data.shape
                    elif not c1 and c2:
                        self.image = toColor(self.image)
                        s1 = self.image[0].shape
                    if s1 != s2:
                        #NEW LAYER SHAPE DOESNT FIT EXISTING:
                        ###show DIALOG#####
                        d = DifferentShapeDialog(name, s1, s2)
                        d.exec_()
                        
                        r = d.opt                
                        if r == d.optNewDisplay:
                            self.moveLayerToNewImage = index
                            return
                        elif r == d.optCut:
                            data =  data[0:s1[0],0:s1[1]]
                            if data.shape != s1:
                                d = np.zeros(s1)
                                d[0:s2[0], 0:s2[1]]=data
                                data = d
                        elif r == d.optResize:
                            data = cv2.resize(data, (s1[1],s1[0])) 
                        
                        elif r == d.optWarp:
                            data = PerspectiveTransformation(self.image[-1]).fitImg(data)
    
                    self.image = np.insert(self.image, index, data, axis=0)

            self.currentIndex = index
            self.setImage(self.image)
            return self.image[index]
Ejemplo n.º 2
0
    def insertLayer(self, index, name=None, data=None):
        '''
        insert a new image as layer
        ...add new / override existing layer
        ...show dialog when data.shape != self.image.shape
        '''
        if data is not None:
            try:
                self.image = np.insert(self.image, index, data, axis=0)

            except IndexError:
                index = -1
                self.image = np.insert(self.image, index, data, axis=0)

            except (ValueError, MemoryError):
                if index == 0 and len(self.image) == 1:
                    # replace, if only has one layer
                    self.image = np.expand_dims(data, axis=0)
                else:
                    if isinstance(data, list):
                        data = data[0]

                    s1 = self.image[0].shape
                    s2 = data.shape
                    # LAYER COLOR IS DIFFERENT:
                    c1 = isColor(self.image[0])
                    c2 = isColor(data)
                    if c1 and not c2:
                        data = toColor(data)
                        s2 = data.shape
                    elif not c1 and c2:
                        self.image = toColor(self.image)
                        s1 = self.image[0].shape
                    if s1 != s2:
                        if isRot90(s1, s2):
                            print('Image is rotated 90DEG.')
                            data = rot90(data)
                        else:
                            # NEW LAYER SHAPE DOESNT FIT EXISTING:
                            ###show DIALOG#####
                            d = DifferentShapeDialog(name, s1, s2)
                            d.exec_()

                            r = d.opt
                            if r == d.optNewDisplay:
                                self.moveLayerToNewImage = index
                                return
                            elif r == d.optCut:
                                data = data[0:s1[0], 0:s1[1]]
                                if data.shape != s1:
                                    d = np.zeros(s1)
                                    d[0:s2[0], 0:s2[1]] = data
                                    data = d
                            elif r == d.optResize:
                                data = cv2.resize(data, (s1[1], s1[0]))

                            elif r == d.optWarp:
                                data = PerspectiveImageStitching(
                                    self.image[-1]).fitImg(data)

                    self.image = np.insert(self.image, index, data, axis=0)

            self.currentIndex = index
            self.setImage(self.image)
            return self.image[index]
Ejemplo n.º 3
0
 def activate(self):
     w = self.display.widget
     w.setImage(toColor(w.image))
Ejemplo n.º 4
0
 def activate(self):
     w = self.display.widget
     w.setImage(toColor(w.image))