def render_subtitle(element, elements): if hasattr( element, "subtitle" ) and element.config["subtitle_type"] == "render" and element.subtitle: subtitle = gst.element_factory_make("textoverlay") elements.append(subtitle) Annotate.add_subtitle(element, subtitle, element.subtitle, element.config)
def getCellTypes(self): """ Annotates single cell types at each level and adds the result to the object. """ scData = Utils.convertAnnDataToDf(self.scData) scData = scData.loc[self._genesIntersect] refDataset = self.refDataset.loc[self._genesIntersect] self.scAnnot = Annotate.annotateCells(scData, refDataset, self.refAnnot, self.deAll) self.scData.obs["cellType"] = self.scAnnot["cellType"]
def get_bin(self, duration=None): if duration is None: duration = self.duration src = gst.element_factory_make("videotestsrc") src.props.pattern = "black" src.props.foreground_color = 0; src.props.background_color = 0; caps= gst.element_factory_make("capsfilter") caps.props.caps = self.config.get_video_caps("AYUV") elements = [src, caps] if self.name == "titlebar": if self.title1: textoverlay = gst.element_factory_make("textoverlay") Annotate.add_title(self, textoverlay, self.title1, "top_title", self.config) elements.append(textoverlay) if self.title2: textoverlay = gst.element_factory_make("textoverlay") Annotate.add_title(self, textoverlay, self.title2, "bottom_title", self.config) elements.append(textoverlay) else: textoverlay = gst.element_factory_make("textoverlay") Annotate.add_title(self, textoverlay, self.title1, "title", self.config) elements.append(textoverlay) process_effects(self, duration, elements) bin = gst.Bin() bin.add(*elements) gst.element_link_many(*elements) bin.add_pad(gst.GhostPad("src", elements[-1].get_pad("src"))) return bin
def process_effects(element, duration, elements, custom_config={}): #if not(custom_config): # caps = gst.element_factory_make("capsfilter") # elements.append(caps) # caps.set_property("caps", element.config.get_video_caps("AYUV", custom_config)) # elements.append(gst.element_factory_make("ffmpegcolorspace")) # #elements.append(gst.element_factory_make("frei0r-filter-bw0r")) # #elements.append(gst.element_factory_make("frei0r-filter-cartoon")) # #elements.append(gst.element_factory_make("frei0r-filter-scale0tilt")) # elements.append(gst.element_factory_make("agingtv")) # elements.append(gst.element_factory_make("ffmpegcolorspace")) # caps = gst.element_factory_make("capsfilter") # elements.append(caps) # caps.set_property("caps", element.config.get_video_caps("AYUV",custom_config)) Annotate.add_annotations(element, duration, elements) render_subtitle(element, elements) caps = gst.element_factory_make("capsfilter") elements.append(caps) caps.set_property("caps", element.config.get_video_caps("AYUV", custom_config)) for gst_element in elements: if gst_element.get_name().startswith("kenburns"): KenBurns.configure_kenburns(element, gst_element, duration)
def get_bin(self, duration=None): if duration is None: duration = self.duration src = gst.element_factory_make("videotestsrc") src.props.pattern = "black" src.props.foreground_color = 0 src.props.background_color = 0 caps = gst.element_factory_make("capsfilter") caps.props.caps = self.config.get_video_caps("AYUV") elements = [src, caps] if self.name == "titlebar": if self.title1: textoverlay = gst.element_factory_make("textoverlay") Annotate.add_title(self, textoverlay, self.title1, "top_title", self.config) elements.append(textoverlay) if self.title2: textoverlay = gst.element_factory_make("textoverlay") Annotate.add_title(self, textoverlay, self.title2, "bottom_title", self.config) elements.append(textoverlay) else: textoverlay = gst.element_factory_make("textoverlay") Annotate.add_title(self, textoverlay, self.title1, "title", self.config) elements.append(textoverlay) process_effects(self, duration, elements) bin = gst.Bin() bin.add(*elements) gst.element_link_many(*elements) bin.add_pad(gst.GhostPad("src", elements[-1].get_pad("src"))) return bin
axes = axs.AxesSequence() for i,ax in zip(range(axialPETIM.shape[0]),axes): ax.imshow(axialPETIM[i,:,:],cmap='hot',interpolation='bicubic') ax.set_title('zlice: {}'.format(i)) axes.show() zslices = axes.selected_slices del axes Nslice = zslices[1]-zslices[0]+1 center_zslice = int(zslices[0] + 0.5*Nslice) theIM = axialPETIM[center_zslice,:,:] plt.imshow(theIM,cmap='hot',interpolation='bicubic') a = ant.Annotate() plt.show() # plot the ROI image rx0,ry0,rx1,ry1=[int(val) for val in [a.x0,a.y0,a.x1,a.y1]] theROI = theIM[ry0:ry1,rx0:rx1] plt.imshow(theROI,cmap='hot',interpolation='bicubic') plt.show() print rx0,ry0,rx1,ry1 # double check if the VOI covers the entire tumor for n in range(zslices[0],zslices[1],1): theROI = axialPETIM[n,ry0:ry1, rx0:rx1] plt.imshow(theROI,cmap='hot',interpolation='bicubic') plt.show()
def main(): fdir = sys.argv[1] imdir = int(sys.argv[2]) Nslice = int(sys.argv[3]) soffset = int(sys.argv[4]) isscrecon = int(sys.argv[5]) # Get a DICOM volume if isscrecon == 0: xc, yc, zc, dxyz, nxyz, vol = GetDcmVol(fdir, False) else: xc, yc, zc, dxyz, nxyz, vol = GetDcmVol(fdir) print xc, yc, zc, nxyz # Get an image in a given direction and show the image if imdir == 2: imindx = xc - 10 elif imdir == 0: imindx = zc else: imindx = yc theIM = ivfit.Get2DPlane(vol, imdir, imindx + soffset) plt.imshow(theIM, cmap='hot', interpolation='bicubic') print theIM.shape # Select a ROI in the image a = ant.Annotate() plt.show() # plot the ROI image rx0, ry0, rx1, ry1 = [int(val) for val in [a.x0, a.y0, a.x1, a.y1]] theROI = theIM[ry0:ry1, rx0:rx1] plt.imshow(theROI, cmap='hot', interpolation='bicubic') # get the correct pixel dimension thedxyz = np.take(dxyz, [2, 1, 0]) theiax = np.arange(len(thedxyz)) oh = theiax[theiax != imdir] thedxy = np.take(thedxyz, oh) print thedxy statscombo1 = np.empty((Nslice + 2, 5)) statscombo2 = np.empty((Nslice + 2, 5)) # determine the slice # to look at halfNslice = int(math.floor(Nslice / 2.)) imindx0 = imindx + soffset if Nslice % 2. == 0: lnslice = np.arange(imindx0 - halfNslice, imindx0 + halfNslice, 1) else: lnslice = np.arange(imindx0 - halfNslice, imindx0 + halfNslice + 1, 1) for ii in range(len(lnslice)): if ii == 0: ioi = theROI else: theIM = ivfit.Get2DPlane(vol, imdir, lnslice[ii]) ioi = theIM[ry0:ry1, rx0:rx1] for ldir in range(2): # Get the line spread function of the ROI image xdata, ydata, demoim = ivfit.ShowLineProfile(ioi, ldir) plt.imshow(demoim, cmap='hot', interpolation='bicubic') xfit, yfit, A, x0, sigma, r2, fwhm = ivfit.GaussFit_lsq( xdata, ydata, thedxy[ldir], isplot=True) print A, x0, sigma, 'Gaussian fit r2 = {}, FWHM = {} mm'.format( r2, fwhm) if ldir == 0: statscombo2[ii, :] = [A, x0, sigma, r2, fwhm] else: statscombo1[ii, :] = [A, x0, sigma, r2, fwhm] # append the mean and stdev statscombo1[-2] = np.mean(statscombo1[:-2], axis=0, dtype=np.float64) statscombo1[-1] = np.std(statscombo1[:-2], axis=0, dtype=np.float64) statscombo2[-2] = np.mean(statscombo2[:-2], axis=0, dtype=np.float64) statscombo2[-1] = np.std(statscombo2[:-2], axis=0, dtype=np.float64) statsall = np.hstack((statscombo1, statscombo2)) # get all the info into a data frame rowname = [str(i) for i in lnslice] + ['mean', 'stdev'] #print rowname if imdir == 0: colname = [ 'A', 'x0', 'sigma', 'R2', 'X-dir FWHM (mm)', 'A', 'x0', 'sigma', 'R2', 'Y-dir FWHM (mm)' ] elif imdir == 2: colname = [ 'A', 'x0', 'sigma', 'R2', 'Y-dir FWHM (mm)', 'A', 'x0', 'sigma', 'R2', 'Z-dir FWHM (mm)' ] df = ps.DataFrame(statsall, index=rowname, columns=colname) wfdir = '/Users/shuang/Documents/Proj_PETMR/Data/Measurement_SpatRes' froot = '/Users/shuang/Documents/Proj_PETMR/IM' tmp = re.findall(r'{}/(.+)*'.format(froot), fdir) if tmp: # make sure the fdir string can be parsed tag = tmp[0].replace('/', '_') file = '{}/SpaRes_{}.csv'.format(wfdir, tag) df.to_csv(file)
def render_subtitle(element, elements): if hasattr(element, "subtitle") and element.config["subtitle_type"] == "render" and element.subtitle: subtitle = gst.element_factory_make("textoverlay") elements.append(subtitle) Annotate.add_subtitle(element, subtitle, element.subtitle, element.config)
def main(): fdir = sys.argv[1] imdir = int(sys.argv[2]) soffset = int(sys.argv[3]) isscrecon = int(sys.argv[4]) # Get a DICOM volume if isscrecon == 0: xc, yc, zc, dxyz, nxyz, vol = GetDcmVol(fdir, False) else: xc, yc, zc, dxyz, nxyz, vol = GetDcmVol(fdir) print xc, yc, zc, nxyz # Get an image in a given direction and show the image if imdir == 2: imindx = xc - 10 elif imdir == 0: imindx = zc else: imindx = yc theIM = ivfit.Get2DPlane(vol, imdir, imindx + soffset) plt.imshow(theIM, cmap='hot', interpolation='bicubic') print theIM.shape # Select a ROI in the image a = ant.Annotate() plt.show() # plot the ROI image rx0, ry0, rx1, ry1 = [int(val) for val in [a.x0, a.y0, a.x1, a.y1]] theROI = theIM[ry0:ry1, rx0:rx1] plt.imshow(theROI, cmap='hot', interpolation='bicubic') # get the correct pixel dimension thedxyz = np.take(dxyz, [2, 1, 0]) theiax = np.arange(len(thedxyz)) oh = theiax[theiax != imdir] thedxy = np.take(thedxyz, oh) # get the line profile and fit a Gaussian via leastsq #wfdir = '/Users/shuang/Documents/Proj_PETMR/Data/Measurement_SpatRes' wfdir = '/Users/shuang/Documents/UCSF/Conference/IEEE2014/Poster' # get file tag froot = '/Users/shuang/Documents/Proj_PETMR/IM' tmp = re.findall(r'{}/(.+)*'.format(froot), fdir) if tmp: # make sure the fdir string can be parsed tag = tmp[0].replace('/', '_') # save the original ROI image fig = plt.figure(1, figsize=(10, 10)) ax = fig.add_subplot(111) plt.imshow(theROI, cmap='hot', interpolation='bicubic') plt.xticks([]) plt.yticks([]) imname = '{}/theROI_{}.pdf'.format(wfdir, tag) print imname plt.savefig(imname) for ldir in range(2): # Get the line spread function of the ROI image xdata, ydata, demoim = ivfit.ShowLineProfile(theROI, ldir) nydata = ydata / np.amax(ydata) fig = plt.figure(2, figsize=(8, 8)) ax = fig.add_subplot(111) plt.imshow(demoim, cmap='hot', interpolation='bicubic') imname = '{}/demoim_{}_imdir{:d}_ldir{:d}.pdf'.format( wfdir, tag, imdir, ldir) print imname plt.savefig(imname) xfit, yfit, A, x0, sigma, r2, fwhm = ivfit.GaussFit_lsq( xdata, nydata, thedxy[ldir]) print A, x0, sigma, 'Gaussian fit r2 = {}, FWHM = {} mm'.format( r2, fwhm) print xfit, yfit #wfname1 = '{}/LSP_{}_imdir{:d}_ldir{:d}.txt'.format(wfdir,tag,imdir,ldir) #np.savetxt(wfname1,(xdata[:,np.newaxis],ydata[:,np.newaxis]),delimiter='\t') #wfname2 = '{}/fitLSP_{}_imdir{:d}_ldir{:d}.txt'.format(wfdir,tag,imdir,ldir) #np.savetxt(wfname2,(xfit,yfit),delimiter='\t') # plot the profile fig = plt.figure(3, figsize=(11, 8)) ax = fig.add_subplot(111) plt.rc('lines', linewidth=3) plt.rc('axes', linewidth=3) plt.tick_params(labelsize=20) pixdim = 10 * dxyz[0] p1 = plt.plot(pixdim * xdata, nydata, linestyle='None', color='b', marker='o', markersize=6.0, label='Original Data') p2 = plt.plot(pixdim * xfit, yfit, color='r', marker='None', label='Fitted Data') axes = plt.gca() axes.set_ylim([0, np.amax(yfit)]) plt.xlabel('Distance (mm)', fontsize=30) plt.ylabel('Relative intensity', fontsize=30) plt.legend(fontsize=30, loc='best') figname = '{}/LSP_{}_imdir{:d}_ldir{:d}.pdf'.format( wfdir, tag, imdir, ldir) print figname plt.savefig(figname) plt.show()
def contextMenuEvent(self, event): menu = QMenu(self) #creates a menu that opens when table is right-clicked ###Options added to menu### boxAction = menu.addAction("Box Plot") scatterAction = menu.addAction("Scatter Plot") menu.addSeparator() AnnotateAction = menu.addAction("Annotate") menu.addSeparator() ReNameAction = menu.addAction("Rename") printNameAction = menu.addAction("Name?") printAction = menu.addAction("Print Row") menu.addSeparator() resetAction = menu.addAction("Reset Table") quitAction = menu.addAction("Close Table") menu.addSeparator() checkAttributesAction = menu.addAction("Properties") ###checkAttributes open a settings-esque window action = menu.exec_(self.mapToGlobal(event.pos())) #tracks the mouse and saves the position of an event(action) if action == quitAction: #close table self.deleteLater() elif action == printAction: #outputs the selected row to the console self.selected = self.selectedItems() #selected items refers to the selection behavior and will be a row of QTable items n = len(self.selected) print("n is {}".format(n)) # to use Qtable Items must be converted from item -> string -> float for i in range(n): self.selected[i] = str(self.selected[i].text()) for i in range(n): self.selected[i] = float(self.selected[i]) print(self.selected) ###Attribute Naming related actions### elif action == resetAction: #if any changes (i.e removing value from Qtable) user can reset to its original data for i in range(self.LenRowIndex): # DataValues grabs a row of data from dataframe DataValues = self.data.iloc[i, :] print("values are {}".format(DataValues)) # converts these values into list format ValList = DataValues.values.tolist() # loops through DataValues list and assigns it to the appropriate cell in the QTable, to 3 significant digits for j in range(0, self.LenColHeaders): item = QTableWidgetItem(str(round(ValList[j], 6))) self.setItem(i, j, item) elif action == ReNameAction: #action lets you change the name of the table self.openPop = TableUI.TablePopup() #create an instance of the tableUI self.openPop.show() self.openPop.TableString.connect(self.RenameTable) #runs the rename method elif action == checkAttributesAction: print("Opening table properties") self.selected = self.selectedItems() #sets variable selected to be the row highlighted when clicked self.Row_Selection = self.row(self.selected[1]) print(self.Row_Selection) try: #create object using module TableAttritbutesWin.py, pass arg table name, statistics, row index number self.AttributesWindow = TableAttributesWin.AttributesDialog(self.name, self.StatsInfo,self.Row_Selection) self.AttributesWindow.show() except Exception as TableAttErr: print("error occured when creating the Table Attritbute window.......ERROR: {}".format(TableAttErr)) elif action == printNameAction: #returns name of table via console print(self.name) elif action == AnnotateAction: print("Annotation has been called") self.AnnotatedWin = Annotate.TextBoxAnnotation() self.AnnotatedWin.exec_() self.AnnotationList.append(self.AnnotatedWin.Annotation) print(self.AnnotationList) print("annotations have been appended to list") self.AnnotationSignal.emit(self.AnnotationList) print("signal has been emitted") ###GRAPHING COMMANDS### elif action == boxAction: print("Box Plot Called from context menu") try: self.selected = self.selectedItems() self.RowNum = self.currentRow() #reports what row of the QtableWidget we selected print(self.RowNum) n = len(self.selected) for i in range(n): self.selected[i] = str(self.selected[i].text()) for i in range(n): if self.selected[i] != "": #if the selected has empty string values they are replace with float nulls self.selected[i] = float(self.selected[i]) else: self.selected[i] = np.nan pass print("right before plotter called") self.BoxDataSignal.emit(self.selected, self.StatsInfo, self.RowNum) #emit signal carrying all the data to be plotted except Exception as boxSignalErr: print("Right when box plot is called an error cccurs and crashes the program. ERROR: {}".format(boxSignalErr)) elif action == scatterAction: print("Scatter Plot Called from context menu") self.selected = self.selectedItems() n = len(self.selected) for i in range(n): self.selected[i] = str(self.selected[i].text()) for i in range(n): if self.selected[i] != "": self.selected[i] = float(self.selected[i]) else: self.selected[i] = np.nan pass print("right before plotter called") self.ScatterDataSignal.emit(self.selected, self.ColHeaders) #emit signal carrying all the data to be plotted else: print("A menu action was not clicked")