Beispiel #1
0
def open_rois(filename=None):
    """
    Open an roi.txt file, creates ROI objects and places them in the current Window.
    
    Args:
        filename (str): The filename (including full path) of the roi.txt file.

    Returns:
        list of rois

    """
    if filename is None:
        filetypes = '*.txt'
        prompt = 'Load ROIs from file'
        filename = open_file_gui(prompt, filetypes=filetypes)
        if filename is None:
            return None
    text = open(filename, 'r').read()
    rois = []
    kind = None
    pts = None
    for text_line in text.split('\n'):
        if kind is None:
            kind = text_line
            pts = []
        elif text_line == '':
            roi = makeROI(kind, pts)
            rois.append(roi)
            kind = None
            pts = None
        else:
            pts.append(tuple(int(float(i)) for i in text_line.split()))

    return rois
    def __call__(self,
                 inputChoice,
                 keepOriginalWindow,
                 keepSourceWindow=False):
        g.settings['volumeSlider']['inputChoice'] = inputChoice
        g.settings['volumeSlider']['keepOriginalWindow'] = keepOriginalWindow

        g.m.statusBar().showMessage("Starting Volume Slider...")

        if inputChoice == 'Current Window':
            camVolumeSlider.startVolumeSlider(keepWindow=keepOriginalWindow)

        elif inputChoice == 'Numpy Array':
            A_path = open_file_gui(directory=os.path.expanduser("~/Desktop"),
                                   filetypes='*.npy')
            g.m.statusBar().showMessage("Importing Array: " + A_path)
            A = np.load(str(A_path))
            camVolumeSlider.startVolumeSlider(A=A,
                                              keepWindow=keepOriginalWindow)

        elif inputChoice == 'Batch Process':
            g.m.statusBar().showMessage("Starting Batch Processing...")
            camVolumeSlider.startVolumeSlider(batch=True)

        return
Beispiel #3
0
 def gui(self):
     filetypes = 'Image Files (*.tif *.tiff);;All Files (*.*)'
     prompt = 'Open File'
     self.filename = open_file_gui(prompt, filetypes=filetypes)
     if self.filename is None:
         return None
     
     self.openTiff(self.filename)    
Beispiel #4
0
 def gui(self):
     filetypes = 'Image Files (*.tif *.tiff);;All Files (*.*)'
     prompt = 'Open File'
     filename = open_file_gui(prompt, filetypes=filetypes)
     if filename is None:
         return None
     
     self.openTiff(filename) 
     
     self.sclicesPerVolume = int(self.nFrames*self.nChannels / self.nVolumes)
     return (self.nChannels, self.nVolumes, self.sclicesPerVolume)
    def gui(self):
        filetypes = 'Image Files (*.tif *.tiff);;All Files (*.*)'
        prompt = 'Open File'
        filename = open_file_gui(prompt, filetypes=filetypes)
        if filename is None:
            return None

        self.openTiff(filename)

        if self.errorFlag:
            return None

        return (self.nChannels, self.nVolumes, self.sclicesPerVolume,
                self.channel1_array, self.channel2_array)
Beispiel #6
0
    def load_classifications(self, filename=None):
        if filename is None:
            filename = open_file_gui("Open classifications",
                                     filetypes='*.json')
        if filename is None:
            return None
        obj_text = codecs.open(filename, 'r', encoding='utf-8').read()
        data = json.loads(obj_text)
        roi_states = np.array(data['states'])

        if len(roi_states) != len(self.window_states):
            g.alert(
                'The number of ROIs in this file does not match the number of ROIs in the image. Cannot import classifications'
            )
        else:
            g.quantimus.roiStates = np.copy(roi_states)
            self.window_states = np.copy(roi_states)
            self.set_roi_states()
Beispiel #7
0
    def __call__(self,
                 inputChoice,
                 keepOriginalWindow,
                 preProcess,
                 slicesPerVolume,
                 slicesDeletedPerVolume,
                 slicesDeletedPerMovie,
                 overlay,
                 overlayStart,
                 keepSourceWindow=False):
        g.settings['volumeSlider']['inputChoice'] = inputChoice
        g.settings['volumeSlider']['keepOriginalWindow'] = keepOriginalWindow
        g.settings['volumeSlider']['preProcess'] = preProcess
        g.settings['volumeSlider']['slicesPerVolume'] = slicesPerVolume
        g.settings['volumeSlider'][
            'slicesDeletedPerVolume'] = slicesDeletedPerVolume
        g.settings['volumeSlider'][
            'slicesDeletedPerMovie'] = slicesDeletedPerMovie
        g.settings['volumeSlider']['overlay'] = overlay
        g.settings['volumeSlider']['overlayStart'] = overlayStart

        g.m.statusBar().showMessage("Starting Volume Slider...")

        if inputChoice == 'Current Window':
            windowName = g.win.filename
            #Get overlay
            if overlay:
                A = np.array(deepcopy(g.win.image))
                print(A.shape)
                endFrame = g.win.mt - 1
                g.win.close()
                #overlayWin =  Window(A[overlayStart:endFrame,:,:],'Overlay')
                dataWin = Window(A[0:overlayStart, :, :], 'Overlay')

            #Trim movie
            if preProcess and slicesDeletedPerMovie != 0:
                trim(0, slicesDeletedPerMovie, delete=True)

            camVolumeSlider.setFileName(windowName)

            #start volumeSlider
            if overlay:
                camVolumeSlider.startVolumeSlider(
                    keepWindow=keepOriginalWindow,
                    preProcess=preProcess,
                    framesPerVol=slicesPerVolume,
                    framesToDelete=slicesDeletedPerVolume,
                    overlayEmbeded=True,
                    A_overlay=A[overlayStart:endFrame, :, :])

            else:
                camVolumeSlider.startVolumeSlider(
                    keepWindow=keepOriginalWindow,
                    preProcess=preProcess,
                    framesPerVol=slicesPerVolume,
                    framesToDelete=slicesDeletedPerVolume)

            #print('loading:',windowName)

        elif inputChoice == 'Numpy Array':
            A_path = open_file_gui(directory=os.path.expanduser("~/Desktop"),
                                   filetypes='*.npy')
            g.m.statusBar().showMessage("Importing Array: " + A_path)
            A = np.load(str(A_path))
            camVolumeSlider.setFileName(A_path)
            camVolumeSlider.startVolumeSlider(A=A,
                                              keepWindow=keepOriginalWindow)

        elif inputChoice == 'Batch Process':
            g.m.statusBar().showMessage("Starting Batch Processing...")
            camVolumeSlider.startVolumeSlider(batch=True)

        elif inputChoice == 'Load file':
            g.m.statusBar().showMessage("Loading file...")
            #Open file using tiff loader
            load_tiff.gui()

            #Get overlay
            if overlay:
                A = np.array(deepcopy(g.win.image))
                print(A.shape)
                endFrame = g.win.mt - 1
                g.win.close()
                #overlayWin =  Window(A[overlayStart:endFrame,:,:],'Overlay')
                dataWin = Window(A[0:overlayStart, :, :], 'Overlay')

            #Trim movie
            if preProcess and slicesDeletedPerMovie != 0:
                trim(0, slicesDeletedPerMovie, delete=True)

            #start volumeSlider
            camVolumeSlider.setFileName(load_tiff.getFileName())

            if overlay:
                camVolumeSlider.startVolumeSlider(
                    keepWindow=keepOriginalWindow,
                    preProcess=preProcess,
                    framesPerVol=slicesPerVolume,
                    framesToDelete=slicesDeletedPerVolume,
                    overlayEmbeded=True,
                    A_overlay=A[overlayStart:endFrame, :, :])

            else:
                camVolumeSlider.startVolumeSlider(
                    keepWindow=keepOriginalWindow,
                    preProcess=preProcess,
                    framesPerVol=slicesPerVolume,
                    framesToDelete=slicesDeletedPerVolume)

        return