def overlayHRS(self, brain, trial, view=1): if view == 1: fun = self.vtkView.overlay elif view == 2: fun = self.vtkView2.overlay else: fun = self.vtkView.overlay brain = brain[0] trial = trial[0] data1 = DataIO.LSMLoad(self.project.brain[brain].trial[trial].dataFile) data2 = DataIO.LSMLoad(self.project.brain[brain].highResScan.dataFile) data2 = [data2[0][::-1, :, :].copy(order='C')] data1 = [ self.resampleData(data1[i], data2[0], data2[0].shape) for i in range(len(data1)) ] transforms1 = self.project.brain[brain].trial[trial].transforms transforms2 = self.project.brain[brain].highResScan.transforms fun(data1=data1, transforms1=transforms1, data2=data2, transforms2=transforms2, colormap='OverlayHRS')
def overlayVOIHRS(self, brain, trial, view): """ camphorapp.overlayVOIHRS(brain, trial, view) This function overlays the VOIs of a single target trial on top of the high-resolution scan If the filter that has been used to extract the VOIs (the VOIfilter object of the target trialData object) allows for a control widget, this also spawns the control widget and passes it to vtkView so that it can be destroyed when new data is created :param brain: brain index of the target trial (as list) :param trial: trial index of the target trial (as list) :param view: index of the vtkView in which to display the data :return: nothing """ brain = brain[0] trial = trial[0] f = self.project.brain[brain].trial[trial].VOIfilter() f._parameters = self.project.brain[brain].trial[trial].VOIfilterParams if view == 1: fun = self.vtkView.overlayVOIsOnStack VOIPanel = self.vtkView.VOIPanel elif view == 2: fun = self.vtkView2.overlayVOIsOnStack VOIPanel = self.vtkView2.VOIPanel else: fun = self.vtkView.overlayVOIsOnStack VOIPanel = self.vtkView.VOIPanel VOIdata = self.project.brain[brain].trial[trial].VOIdata.astype( numpy.uint8) VOIbase = self.project.brain[brain].trial[trial].VOIbase stackData = DataIO.LSMLoad( self.project.brain[brain].highResScan.dataFile) stackData = [stackData[0][::-1, :, :].copy(order='C')] VOIdata = [ self.resampleData(VOIdata, stackData[0], stackData[0].shape) ] VOIbase = self.resampleData(VOIbase, stackData[0], stackData[0].shape) stackTransforms = self.project.brain[brain].highResScan.transforms fun(VOIdata=VOIdata, stackData=stackData, stackTransforms=stackTransforms, colormap='Standard') VOIPanel = f.controlWidget( self, VOIbase, VOIdata[0], message='[View {:d}] brain{:d}/trial{:d}'.format( view, brain[i], trial[i]), dockArea=self.VOIPanelDockArea) if view == 1: self.vtkView.VOIPanel = VOIPanel elif view == 2: self.vtkView2.VOIPanel = VOIPanel else: self.vtkView.VOIPanel = VOIPanel
def overlay(self, brain, trial, view=1): if view == 1: fun = self.vtkView.overlay elif view == 2: fun = self.vtkView2.overlay else: fun = self.vtkView.overlay data1 = DataIO.LSMLoad( self.project.brain[brain[0]].trial[trial[0]].dataFile) data2 = DataIO.LSMLoad( self.project.brain[brain[1]].trial[trial[1]].dataFile) transforms1 = self.project.brain[brain[0]].trial[trial[0]].transforms transforms2 = self.project.brain[brain[1]].trial[trial[1]].transforms fun(data1=data1, transforms1=transforms1, data2=data2, transforms2=transforms2)
def averageTrials(self, brain, trial, view): """ camphorapp.averageTrials(brain, trial, view) This function displays the average of the selected trials in the specified view For efficiency, the average is computed here and passed to the vtkView object as stack data :param brain: brain index of the target trials (as list) :param trial: trial index of the target trials (as list) :param view: index of the vtkView in which to display the data :return: nothing """ nTrials = len(brain) stackData = DataIO.LSMLoad(self.project.brain[0].trial[0].dataFile) transforms = self.project.brain[0].trial[0].transforms for t in transforms: if t.active: stackData = t.apply(stackData) averageData = [s.astype(numpy.double) for s in stackData] nFrames = len(stackData) for iTrial in range(1, nTrials): stackData = DataIO.LSMLoad(self.project.brain[brain[iTrial]].trial[ trial[iTrial]].dataFile) transforms = self.project.brain[brain[iTrial]].trial[ trial[iTrial]].transforms for t in transforms: if t.active: stackData = t.apply(stackData) for iFrame in range(nFrames): averageData[iFrame] += stackData[iFrame].astype(numpy.double) if view == 1: self.vtkView.assignData([(a / nTrials).astype(numpy.uint8) for a in averageData]) elif view == 2: self.vtkView2.assignData([(a / nTrials).astype(numpy.uint8) for a in averageData]) else: self.vtkView.assignData([(a / nTrials).astype(numpy.uint8) for a in averageData])
def showtDiff(self, brain, trial, view=1): if view == 1: fun = self.vtkView.showtDiff elif view == 2: fun = self.vtkView2.showtDiff else: fun = self.vtkView.showtDiff data = DataIO.LSMLoad( self.project.brain[brain[0]].trial[trial[0]].dataFile) transforms = self.project.brain[brain[0]].trial[trial[0]].transforms fun(data=data, transforms=transforms)
def execute(self, camphor): # Only first brain, for now brain = range(camphor.project.nBrains) brain = [0] # Determines the total number of trials to do nBrains = len(brain) self.nTotal = 0 for b in brain: self.nTotal += camphor.project.brain[b].nTrials transformlist = [] self.nDone = 0 for b in brain: nTrials = camphor.project.brain[b].nTrials for i in range(nTrials): # 1. Loads the data dataFile = camphor.project.brain[b].trial[i].dataFile data = DataIO.LSMLoad(dataFile) #Applies the existing transforms transforms = camphor.project.brain[b].trial[i].transforms for t in transforms: if(t.active): data = t.apply(data) # 2. Pre-registers self.message('Pre-registering brain {:d}/{:d}, trial {:d}/{:d}'.format(b + 1, nBrains, i + 1, nTrials), progress=100 * self.nDone / self.nTotal) preTransform = self.preRegisterImage(data) # Applies the pre-transforms in order to calculate the "improved" baseline data = preTransform.apply(data) # 2. calculate the mean baseline baseline = self.calculateBaseline(data, endframe=camphor.ini['baseline_endframe']) self.message('Registering brain {:d}/{:d}, trial {:d}/{:d}'.format(b+1, nBrains, i+1, nTrials), progress=100 * (self.nDone+0.5) / self.nTotal) # 3. Register each timeframe to the baseline transformlist.append(self.registerImage(baseline, data, camphor.project.brain[b].trial[i], preTransform)) self.nDone += 1 if self.cancelled: self.cancelled = False self.message('Registration cancelled', progress=100) return None self.message('Registration completed', progress=100) return transformlist
def overlayRawReg(self, brain, trial, view=1): """ Overlays the raw and registered version of the same trial :param brain: :param trial: :param view: :return: """ if view == 1: fun = self.vtkView.overlay elif view == 2: fun = self.vtkView2.overlay else: fun = self.vtkView.overlay data = DataIO.LSMLoad(self.project.brain[brain].trial[trial].dataFile) transforms = self.project.brain[brain].trial[trial].transforms fun(data1=data, transforms1=transforms, data2=data)
def execute(self, camphor): # Only first brain, for now brain = range(camphor.project.nBrains) brain = [0] # Determines the total number of trials to do nBrains = len(brain) self.nTotal = 0 for b in brain: self.nTotal += camphor.project.brain[b].nTrials transformlist = [] self.nDone = 0 for b in brain: nTrials = camphor.project.brain[b].nTrials for iTrial in range(nTrials): # 1. Loads the data dataFile = camphor.project.brain[b].trial[iTrial].dataFile data = DataIO.LSMLoad(dataFile) #Applies the existing transforms transforms = camphor.project.brain[b].trial[iTrial].transforms for t in transforms: if (t.active): data = t.apply(data) # downscales the data # f = utils.calculatedF(data) # # w = numpy.stack(f) # s = numpy.std(w, 0) # sm = numpy.median(s) # # mask = s > 0.5*sm mask = None # c = [ndimage.gaussian_filter(d, 5, order=0) for d in data] # cf = utils.calculatedF(c) # mask = cf[0]>5 # for i in range(1,len(cf)): # mask = numpy.logical_or(mask,cf[i]>5) # mask = 1-mask # data = c # 2. Pre-registers self.message( 'Pre-registering brain {:d}/{:d}, trial {:d}/{:d}'.format( b + 1, nBrains, iTrial + 1, nTrials), progress=100 * self.nDone / self.nTotal) transformlist.append( self.preRegisterImage( data, camphor.project.brain[b].trial[iTrial], mask=mask)) self.nDone += 1 if self.cancelled: self.cancelled = False self.message('Registration cancelled', progress=100) return None self.message('Registration completed', progress=100) return transformlist
def tAverage(self, brain, trial, view): """ camphorapp.tAverage(brain, trial, view) This function displays the temporal average of the selected trial in the specified view For efficiency, the average is computed here and passed to the vtkView object as stack data :param brain: brain index of the target trials (as list) :param trial: trial index of the target trials (as list) :param view: index of the vtkView in which to display the data :return: nothing """ stackData = DataIO.LSMLoad( self.project.brain[brain[0]].trial[trial[0]].dataFile) transforms = self.project.brain[brain[0]].trial[trial[0]].transforms for t in transforms: if t.active: stackData = t.apply(stackData) averageData = [ numpy.mean(numpy.stack(stackData), 0).astype(numpy.uint8) ] VOIdata = self.project.brain[brain[0]].trial[trial[0]].VOIdata hasVOI = (VOIdata is not None) if hasVOI: VOIbase = self.project.brain[brain[0]].trial[trial[0]].VOIbase f = self.project.brain[brain[0]].trial[trial[0]].VOIfilter() f._parameters = self.project.brain[brain[0]].trial[ trial[0]].VOIfilterParams VOIPanel = f.controlWidget( self, VOIbase, VOIdata, message='[View {:d}] brain{:d}/trial{:d}'.format( view, brain[0], trial[0]), dockArea=self.VOIPanelDockArea) if view == 1: self.vtkView.overlayVOIsOnStack(VOIdata=[VOIdata], stackData=averageData, colormap='Standard', showVOIs=False) self.vtkView.VOIPanel = VOIPanel elif view == 2: self.vtkView2.overlayVOIsOnStack(VOIdata=[VOIdata], stackData=averageData, colormap='Standard', showVOIs=False) self.vtkView2.VOIPanel = VOIPanel else: self.vtkView.overlayVOIsOnStack(VOIdata=[VOIdata], stackData=averageData, colormap='Standard', showVOIs=False) self.vtkView.VOIPanel = VOIPanel else: if view == 1: self.vtkView.assignData(averageData) elif view == 2: self.vtkView2.assignData(averageData) else: self.vtkView.assignData(averageData)
def openFile(self, dub=None, file=None, view=0, transforms=(), flip=False): """ camphor.openFile() This function summons a file dialog and calls the LSMLoad() function from the dataIO module to load the LSM data :return: """ if file is None: fname = os.path.normpath( QtGui.QFileDialog.getOpenFileName( self, 'Open file', os.path.normpath(self.ini['LOADDIR']), '*.lsm;*.tif')) else: fname = file self.Output("Opening {:s}".format(fname)) if fname != ".": if view == 0: self.rawData = DataIO.LSMLoad(fname) if flip: self.rawData = [ self.rawData[i][::-1, :, :].copy(order='C') for i in range(len(self.rawData)) ] self.dataLoaded = True self.fileName = fname elif view == 1: self.rawData1 = DataIO.LSMLoad(fname) if flip: self.rawData1 = [ self.rawData1[i][::-1, :, :].copy(order='C') for i in range(len(self.rawData1)) ] self.dataLoaded1 = True self.fileName = fname # Renders the loaded data in the VTK plugin self.vtkView.assignData(self.rawData1, transforms=transforms) # Adjusts the window's title if self.dataLoaded2: self.setWindowTitle("{:s} - {:s} - {:s}".format( self.ini['APPNAME'], os.path.basename(self.fileName), os.path.basename(self.fileName2))) else: self.setWindowTitle("{:s} - {:s}".format( self.ini['APPNAME'], os.path.basename(self.fileName))) elif view == 2: self.rawData2 = DataIO.LSMLoad(fname) if flip: self.rawData2 = [ self.rawData2[i][::-1, :, :].copy(order='C') for i in range(len(self.rawData2)) ] self.dataLoaded2 = True self.fileName2 = fname # Renders the loaded data in the VTK plugin self.vtkView2.assignData(self.rawData2, transforms=transforms) # Adjusts the window's title if self.dataLoaded: self.setWindowTitle("{:s} - {:s} - {:s}".format( self.ini['APPNAME'], os.path.basename(self.fileName), os.path.basename(self.fileName2))) else: self.setWindowTitle("{:s} - {:s}".format( self.ini['APPNAME'], os.path.basename(self.fileName2))) else: print("Error: view {:d} requested".format(view))