def open(self, filename):
        import pyfits  # save startup time
        f = pyfits.open(filename)
        img = f[0].data
        labels = None  # f[0].name

        prefs = self.preferences
        # OPEN
        # due to different conventions:
        img = transpose(img)
        # crop
        if prefs.pCrop.value():
            r = (prefs.pCropX0.value(),
                 prefs.pCropX1.value(),
                 prefs.pCropY0.value(),
                 prefs.pCropY1.value())
            img = img[r[0]:r[1], r[2]:r[3]]
        # resize
        if prefs.pResize.value():
            img = cv2.resize(
                img, (prefs.pResizeX.value(), prefs.pResizeY.value()))

        img = self.toFloat(img)

        return img, labels
Exemple #2
0
    def open(self, filename):
        import pyfits #save startup time
        f = pyfits.open(filename)
        img = f[0].data
        labels = None#f[0].name
     
        prefs = self.preferences
        #OPEN
        #due to different conventions:
        img = transpose(img) 
        #crop
        if prefs.pCrop.value():
            r = (prefs.pCropX0.value(),
                 prefs.pCropX1.value(),
                 prefs.pCropY0.value(),
                 prefs.pCropY1.value())
            img = img[r[0]:r[1],r[2]:r[3]]
        #resize  
        if prefs.pResize.value():
            img = cv2.resize(img, (prefs.pResizeX.value(), prefs.pResizeY.value())) 
 
        img = self.toFloat(img) 
         

        return img, labels
    def open(self, filename):
        p = self.preferences
        #open in 8 bit? 
        if p.p8bit.value():
            col = 0
        else:  
            col = cv2.IMREAD_ANYDEPTH
        if p.pGrey.value() and not p.pSplitColors.value():
            col = col | cv2.IMREAD_GRAYSCALE
        else:
            col |= cv2.IMREAD_ANYCOLOR

        #OPEN
        img = cv2.imread(str(filename), col) #cv2.IMREAD_UNCHANGED)
        if img is None:
            raise Exception("image '%s' doesn't exist" %filename)
        #due to different conventions:
        img = transpose(img) 
        
        #crop
        if p.pCrop.value():
            r = (p.pCropX0.value(),
                 p.pCropX1.value(),
                 p.pCropY0.value(),
                 p.pCropY1.value())
            img = img[r[0]:r[1],r[2]:r[3]]
        
        #resize  
        if p.pResize.value():
            img = cv2.resize(img, (p.pResizeX.value(), p.pResizeY.value())) 

        labels = None
        if img.ndim == 3:
            if p.pSplitColors.value():
                img = np.transpose(img, axes=(2,0,1))
                labels = ['blue', 'green','red']
            else:
                #rgb convention
                img = cv2.cvtColor(img, cv2.cv.CV_BGR2RGB)

        #change data type to float
        img = self.toFloat(img, p.pToFloat.value(), p.pForceFloat64.value()) 
        return img, labels
Exemple #4
0
    def open(self, filename):
        p = self.preferences
        #open in 8 bit? 
        if p.p8bit.value():
            col = 0
        else:  
            col = cv2.IMREAD_ANYDEPTH
        if p.pGrey.value() and not p.pSplitColors.value():
            col = col | cv2.IMREAD_GRAYSCALE
        else:
            col |= cv2.IMREAD_ANYCOLOR

        #OPEN
        img = cv2.imread(str(filename), col) #cv2.IMREAD_UNCHANGED)
        if img is None:
            raise Exception("image '%s' doesn't exist" %filename)
        #due to different conventions:
        img = transpose(img) 
        
        #crop
        if p.pCrop.value():
            r = (p.pCropX0.value(),
                 p.pCropX1.value(),
                 p.pCropY0.value(),
                 p.pCropY1.value())
            img = img[r[0]:r[1],r[2]:r[3]]
        
        #resize  
        if p.pResize.value():
            img = cv2.resize(img, (p.pResizeX.value(), p.pResizeY.value())) 

        labels = None
        if img.ndim == 3:
            if p.pSplitColors.value():
                img = np.transpose(img, axes=(2,0,1))
                labels = ['blue', 'green','red']
            else:
                #rgb convention
                img = cv2.cvtColor(img, cv2.cv.CV_BGR2RGB)

        #change data type to float
        img = self.toFloat(img) 
        return img, labels
    def open(self, filename):
        prefs = self.preferences
        # OPEN
        tif = TiffFile(str(filename))
        img = tif.asarray()
        # due to different conventions:
        img = transpose(img)
        # crop
        if prefs.pCrop.value():
            r = (prefs.pCropX0.value(),
                 prefs.pCropX1.value(),
                 prefs.pCropY0.value(),
                 prefs.pCropY1.value())
            img = img[r[0]:r[1], r[2]:r[3]]
        # resize
        if prefs.pResize.value():
            img = cv2.resize(
                img, (prefs.pResizeX.value(), prefs.pResizeY.value()))

        img = self.toFloat(img)

        try:
            # try to extract labels names set by imageJ:
            labels = tif.pages[0].imagej_tags['labels']
            # remove surplus information:
            for n, l in enumerate(labels):
                try:
                    i = l.index('\n')
                    if i != -1:
                        labels[n] = l[:i]
                except ValueError:
                    # no \n in label
                    pass

        except AttributeError:
            if img.ndim == 3:
                # color image
                labels = [str(r) for r in range(len(img))]
            else:
                labels = None

        tif.close()
        return img, labels
    def open(self, filename):
        prefs = self.preferences
        #OPEN
        tif = tff.TIFFfile(str(filename))
        img = tif.asarray()
        #due to different conventions:
        img = transpose(img)
        #crop
        if prefs.pCrop.value():
            r = (prefs.pCropX0.value(), prefs.pCropX1.value(),
                 prefs.pCropY0.value(), prefs.pCropY1.value())
            img = img[r[0]:r[1], r[2]:r[3]]
        #resize
        if prefs.pResize.value():
            img = cv2.resize(img,
                             (prefs.pResizeX.value(), prefs.pResizeY.value()))

        img = self.toFloat(img)

        try:
            #try to extract labels names set by imageJ:
            labels = tif.pages[0].imagej_tags['labels']
            #remove surplus information:
            for n, l in enumerate(labels):
                try:
                    i = l.index('\n')
                    if i != -1:
                        labels[n] = l[:i]
                except ValueError:
                    #no \n in label
                    pass

        except AttributeError:
            if img.ndim == 3:
                #color image
                labels = [str(r) for r in range(len(img))]
            else:
                labels = None

        tif.close()
        return img, labels
Exemple #7
0
 def _transpose(self):
     w = self.display.widget
     i = w.image
     w.setImage(transpose(i))
Exemple #8
0
def out(img):
    if ip.ARRAYS_ORDER_IS_XY:
        return transpose(img)
    return img
Exemple #9
0
 def _transpose(self):
     w = self.display.widget
     i = w.image
     w.setImage(transpose(i))
Exemple #10
0
def out(img):
    if ip.ARRAYS_ORDER_IS_XY:
        return transpose(img)
    return img