Exemplo n.º 1
0
 def convert_pst2tif(self,paths):
     """ batch convert .lsm files to tiffs """
     for path in paths:
         io.pst2tiff(path)
         
     tifpaths = [os.path.splitext(path)[0]+'.tif' for path in paths]
     return tifpaths
Exemplo n.º 2
0
    def convert_pst2tif(self, paths):
        """ batch convert .lsm files to tiffs """
        for path in paths:
            io.pst2tiff(path)

        tifpaths = [os.path.splitext(path)[0] + '.tif' for path in paths]
        return tifpaths
Exemplo n.º 3
0
    def write_extraction_mask(self):
        """ write both the .roi file and the tif pages
        ROI file format specification: each row a ROI,
        first col: kw for roi type
        if circle: label, layer, pos x, pos y, diameter
        if poly: label, layer, pos x_1, pos_y1, ... pos x_n, pos y_n
        """
        outpath = self.SaveFileDialog(
            title='saving ROIs',
            default_dir=self.Main.Options.general['cwd'],
            extension='*.roi')
        outpath = self.append_extension(outpath, '.roi')

        fh = open(outpath, 'w')

        # iterate over ROIs
        for i, ROI in enumerate(self.Main.ROIs.ROI_list):
            label = str(ROI.label)

            if type(ROI) == myCircleROI:
                #                pos = sp.array([ROI.pos().x(),ROI.pos().y()])
                #                pos = self.get_ROI_position(ROI)
                x = str(sp.around(ROI.center[0], decimals=2))
                y = str(sp.around(ROI.center[1], decimals=2))
                d = str(sp.around(ROI.diameter, decimals=2))

                fh.write('\t'.join(['circle', label, x, y, d, '\n']))

            if type(ROI) == myPolyLineROI:
                fh.write('\t'.join(['polygon', label]))
                fh.write('\t')

                handle_pos = [tup[1] for tup in ROI.getSceneHandlePositions()]
                pos_mapped = [ROI.ViewBox.mapToView(pos) for pos in handle_pos]

                for pos in (pos_mapped):

                    x = pos.x()
                    y = pos.y()

                    fh.write('\t'.join([
                        str(sp.around(x, decimals=2)),
                        str(sp.around(y, decimals=2))
                    ]))
                    fh.write('\t')
                fh.write('\n')

        fh.close()

        print "saved ROIs in .roi format to", outpath
        #        outpath = os.path.splitext(outpath)[0] + '_mask.tif'
        #        outpath = self.MainWindow.SaveFileDialog(title='saving ROIs',defaultdir=self.path,extension='.tif')

        # extraction mask
        self.Main.Processing.calc_extraction_mask()
        io.save_tstack(self.Main.Data.extraction_mask.astype('uint16'),
                       os.path.splitext(outpath)[0] + '_mask.tif')
        print "saved ROIs in .tif format to", outpath

        pass
Exemplo n.º 4
0
    def write_extraction_mask(self):
        """ write both the .roi file and the tif pages
        ROI file format specification: each row a ROI,
        first col: kw for roi type
        if circle: label, layer, pos x, pos y, diameter
        if poly: label, layer, pos x_1, pos_y1, ... pos x_n, pos y_n
        """
        outpath = self.SaveFileDialog(title='saving ROIs',default_dir = self.Main.Options.general['cwd'], extension='*.roi')
        outpath = self.append_extension(outpath, '.roi')

        fh = open(outpath,'w')

        # iterate over ROIs
        for i,ROI in enumerate(self.Main.ROIs.ROI_list):
            label = str(ROI.label)

            if type(ROI) == myCircleROI:
#                pos = sp.array([ROI.pos().x(),ROI.pos().y()])
#                pos = self.get_ROI_position(ROI)
                x = str(sp.around(ROI.center[0],decimals=2))
                y = str(sp.around(ROI.center[1],decimals=2))
                d = str(sp.around(ROI.diameter,decimals=2))

                fh.write('\t'.join(['circle',label,x,y,d,'\n']))

            if type(ROI) == myPolyLineROI:
                 fh.write('\t'.join(['polygon',label]))
                 fh.write('\t')

                 handle_pos = [tup[1] for tup in ROI.getSceneHandlePositions()]
                 pos_mapped = [ROI.ViewBox.mapToView(pos) for pos in handle_pos]

                 for pos in (pos_mapped):

                     x = pos.x()
                     y = pos.y()

                     fh.write('\t'.join([str(sp.around(x,decimals=2)),str(sp.around(y,decimals=2))]))
                     fh.write('\t')
                 fh.write('\n')

        fh.close()

        print("saved ROIs in .roi format to", outpath)
#        outpath = os.path.splitext(outpath)[0] + '_mask.tif'
#        outpath = self.MainWindow.SaveFileDialog(title='saving ROIs',defaultdir=self.path,extension='.tif')

        # extraction mask
        self.Main.Processing.calc_extraction_mask()
        io.save_tstack(self.Main.Data.extraction_mask.astype('uint16'),os.path.splitext(outpath)[0] + '_mask.tif')
        print("saved ROIs in .tif format to", outpath)

        pass
Exemplo n.º 5
0
 def load_tif(self,paths):
     """ read tifs found at paths (list with paths) """
     
     # reading
     x,y,t = io.read_tiffstack(paths[0]).shape
     n = len(paths)
     
     self.Main.Data.raw = sp.zeros((x,y,t,n),dtype='uint16')
     self.Main.Data.dFF = sp.zeros((x,y,t,n),dtype='float32')
     
     for n,path in enumerate(paths):
         print "loading dataset from " + path
         print "Dataset size: " + str(os.stat(path).st_size / 1000000.0) + ' MB'
         self.Main.MainWindow.statusBar().showMessage("loading dataset: " + path)
         self.Main.Data.raw[:,:,:,n] = io.read_tiffstack(path)
     self.Main.MainWindow.statusBar().clearMessage()
Exemplo n.º 6
0
    def load_tif(self, paths):
        """ read tifs found at paths (list with paths) """

        # reading
        x, y, t = io.read_tiffstack(paths[0]).shape
        n = len(paths)

        self.Main.Data.raw = sp.zeros((x, y, t, n), dtype='uint16')
        self.Main.Data.dFF = sp.zeros((x, y, t, n), dtype='float32')

        for n, path in enumerate(paths):
            print "loading dataset from " + path
            print "Dataset size: " + str(
                os.stat(path).st_size / 1000000.0) + ' MB'
            self.Main.MainWindow.statusBar().showMessage("loading dataset: " +
                                                         path)
            self.Main.Data.raw[:, :, :, n] = io.read_tiffstack(path)
        self.Main.MainWindow.statusBar().clearMessage()
Exemplo n.º 7
0
    def load_nonparametric_ROIs(self, size_filter=None, thresh=0.5):
        """ reads a *_mask.tif 
        size_filter can be a tuple and segments with an area smaller than 
        size_filter[0] or larger size_filter[1] are considered to be valid ROIs
        """
        self.Main.ROIs.reset()

        # get mask data
        file_path = self.OpenFileDialog(
            title='load nonparametric ROIs',
            default_dir=self.Main.Options.general['cwd'],
            extension='*.tif')[0]
        masks = io.read_tiffstack(file_path)

        # skimage based segmentation
        masks_thresh = masks > thresh
        masks_label = sp.zeros(masks_thresh.shape)
        for i in range(masks_thresh.shape[2]):
            masks_label[:, :, i] = sklabel(masks_thresh[:, :, i])

        # split into a array of submasks
        Nsubmasks = [
            int(masks_label[:, :, i].max())
            for i in range(masks_label.shape[2])
        ]
        submasks = sp.zeros((masks.shape[0], masks.shape[1], sum(Nsubmasks)),
                            dtype='bool')

        i = 0
        for j in range(masks_label.shape[2]):
            mask = masks_label[:, :, j]
            for l in range(1, Nsubmasks[j] + 1):
                submasks[mask == l, i] = True
                i += 1

        # for each mask, calculate a contour
        contours = []
        for i in range(submasks.shape[2]):
            contour = find_contours(submasks[:, :, i], level=0.5)
            contours.append(contour)

        # add PolyLineROI
        for i in range(submasks.shape[2]):
            self.Main.ROIs.add_ROI(kind='nonparametric',
                                   label=str(i),
                                   contour=contours[i],
                                   mask=submasks[:, :, i])
            pass
Exemplo n.º 8
0
    def load_nonparametric_ROIs(self,size_filter=None,thresh=0.5):
        """ reads a *_mask.tif 
        size_filter can be a tuple and segments with an area smaller than 
        size_filter[0] or larger size_filter[1] are considered to be valid ROIs
        """
        self.Main.ROIs.reset()    
        
        # get mask data
        file_path = self.OpenFileDialog(title='load nonparametric ROIs',default_dir = self.Main.Options.general['cwd'], extension='*.tif')[0]
        masks = io.read_tiffstack(file_path)
        
        
        
        # skimage based segmentation
        masks_thresh = masks > thresh
        masks_label = sp.zeros(masks_thresh.shape)
        for i in range(masks_thresh.shape[2]):
            masks_label[:,:,i] = sklabel(masks_thresh[:,:,i])
    
        # split into a array of submasks
        Nsubmasks = [int(masks_label[:,:,i].max()) for i in range(masks_label.shape[2])]
        submasks = sp.zeros((masks.shape[0],masks.shape[1],sum(Nsubmasks)),dtype='bool')
        
        i = 0
        for j in range(masks_label.shape[2]):
            mask = masks_label[:,:,j]
            for l in range(1,Nsubmasks[j]+1):
                submasks[mask == l,i] = True
                i += 1

        # for each mask, calculate a contour
        contours = []
        for i in range(submasks.shape[2]):
            contour = find_contours(submasks[:,:,i],level=0.5)
            contours.append(contour)

        
        # add PolyLineROI
        for i in range(submasks.shape[2]):
            self.Main.ROIs.add_ROI(kind='nonparametric',label=str(i),contour=contours[i],mask=submasks[:,:,i])
            pass