def make_calibration_book(self, book): self.calibration_panel = CalibrationPanel(book, 'calibrationpanel') self.calibration_panel.pack(side=tk.TOP, fill=tk.Y, expand=1) self.calibration_panel.register(self) self.calibration_r2map_frame = tk.LabelFrame(self.main_frame, text='R2map') self.calibration_r2map_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.calibration_r2map_img = ImagePanel(self.calibration_r2map_frame, 'calr2mapimg', wl=True, toolbar=True, info=False, cb=True) self.calibration_r2map_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.calibration_r2map_img.register(self) self.calibration_dosemap_frame = tk.LabelFrame(self.main_frame, text='Dose map') self.calibration_dosemap_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.calibration_dosemap_img = ImagePanel(self.calibration_dosemap_frame, 'caldosemapimg', wl=True, toolbar=True, info=False, cb=True) self.calibration_dosemap_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.calibration_dosemap_img.register(self)
def make_project_book(self, book): self.project_panel = ProjectManager(book, 'projectinfo') self.project_panel.register(self) self.img_frame = tk.LabelFrame(self.main_frame, text='Dicom images') self.img_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.dicom_img = ImagePanel(self.img_frame, 'main_img', wl=True, toolbar=True, info=True, cb=True) self.dicom_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
def make_r2map_book(self, book): #toolbaritems = ('Save$icons/Save$tk.FLAT$self.saveR2$tk.LEFT$Save R2 parameters', # 'Exit$icons/Exit$tk.FLAT$self.quit$tk.RIGHT$Exit') #button_bar = self.make_button_bar(book, toolbaritems, tk.TOP) #button_bar.pack(side=tk.TOP, fill=tk.X, expand=0) self.r2map_panel = R2MapPanel(book, self.project_panel, 'r2mappanel') self.r2map_panel.pack(side=tk.TOP, fill=tk.Y, expand=1) self.r2map_panel.register(self) self.r2map_dicom_frame = tk.LabelFrame(self.main_frame, text='Dicom image') self.r2map_dicom_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.r2map_dicom_img = ImagePanel(self.r2map_dicom_frame, 'r2map_dicom_frame', wl=True, toolbar=True, info=False, cb=True) self.r2map_dicom_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.r2map_dicom_img.register(self) self.r2map_frame = tk.LabelFrame(self.main_frame, text='R2map') self.r2map_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.r2map_img = ImagePanel(self.r2map_frame, 'r2map_frame', wl=True, toolbar=True, info=False, cb=True) self.r2map_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
class Gellies(GUIFramework): menuitems = ( 'File- &Exit/Ctrl+q/self.quit', ) def __init__(self, root): GUIFramework.__init__(self, root) self.root = root self.build_GUI() self.r2mapsID = None def build_GUI(self): books = ('Project', 'R2map', 'Calibration') self.left_frame = tk.Frame(self.root) self.left_frame.pack(side=tk.LEFT, fill=tk.Y, expand=0) self.right_frame = tk.Frame(self.root) self.right_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.notebook = ttk.Notebook(self.left_frame) self.notebook.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.book1 = tk.Frame(self.notebook) self.notebook.add(self.book1, text='Project') self.book2 = tk.Frame(self.notebook) self.notebook.add(self.book2, text='R2map') self.book3 = tk.Frame(self.notebook) self.notebook.add(self.book3, text='Calibration') self.notebook.bind('<<NotebookTabChanged>>', self.notebook_changed) self.main_frame = tk.Frame(self.right_frame) self.main_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.make_project_book(self.book1) self.make_r2map_book(self.book2) self.make_calibration_book(self.book3) self.message_box_frame = tk.LabelFrame(self.right_frame, text='Messages') self.message_box_frame.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=1) self.messagebox = MessageBox(self.message_box_frame) self.messagebox.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.r2value = [] self.dose = [] def make_project_book(self, book): self.project_panel = ProjectManager(book, 'projectinfo') self.project_panel.register(self) self.img_frame = tk.LabelFrame(self.main_frame, text='Dicom images') self.img_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.dicom_img = ImagePanel(self.img_frame, 'main_img', wl=True, toolbar=True, info=True, cb=True) self.dicom_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) def make_r2map_book(self, book): #toolbaritems = ('Save$icons/Save$tk.FLAT$self.saveR2$tk.LEFT$Save R2 parameters', # 'Exit$icons/Exit$tk.FLAT$self.quit$tk.RIGHT$Exit') #button_bar = self.make_button_bar(book, toolbaritems, tk.TOP) #button_bar.pack(side=tk.TOP, fill=tk.X, expand=0) self.r2map_panel = R2MapPanel(book, self.project_panel, 'r2mappanel') self.r2map_panel.pack(side=tk.TOP, fill=tk.Y, expand=1) self.r2map_panel.register(self) self.r2map_dicom_frame = tk.LabelFrame(self.main_frame, text='Dicom image') self.r2map_dicom_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.r2map_dicom_img = ImagePanel(self.r2map_dicom_frame, 'r2map_dicom_frame', wl=True, toolbar=True, info=False, cb=True) self.r2map_dicom_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.r2map_dicom_img.register(self) self.r2map_frame = tk.LabelFrame(self.main_frame, text='R2map') self.r2map_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.r2map_img = ImagePanel(self.r2map_frame, 'r2map_frame', wl=True, toolbar=True, info=False, cb=True) self.r2map_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) def make_calibration_book(self, book): self.calibration_panel = CalibrationPanel(book, 'calibrationpanel') self.calibration_panel.pack(side=tk.TOP, fill=tk.Y, expand=1) self.calibration_panel.register(self) self.calibration_r2map_frame = tk.LabelFrame(self.main_frame, text='R2map') self.calibration_r2map_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.calibration_r2map_img = ImagePanel(self.calibration_r2map_frame, 'calr2mapimg', wl=True, toolbar=True, info=False, cb=True) self.calibration_r2map_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.calibration_r2map_img.register(self) self.calibration_dosemap_frame = tk.LabelFrame(self.main_frame, text='Dose map') self.calibration_dosemap_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.calibration_dosemap_img = ImagePanel(self.calibration_dosemap_frame, 'caldosemapimg', wl=True, toolbar=True, info=False, cb=True) self.calibration_dosemap_img.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.calibration_dosemap_img.register(self) def notebook_changed(self, event): book = self.notebook.index(self.notebook.select()) print(book) if book == 0: print('Book 1') for child in self.main_frame.winfo_children(): child.pack_forget() self.img_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=1) if book == 1: print('Book 2') for child in self.main_frame.winfo_children()[:-1]: child.pack_forget() self.r2map_dicom_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.r2map_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) if book == 2: print('Book 3') for child in self.main_frame.winfo_children(): child.pack_forget() self.calibration_r2map_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.calibration_dosemap_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) def quit(self): self.root.quit() def update_(self, name, event): print(name, event) if name == 'projectinfo': if event == 'NewProject': self.messagebox.config(state=tk.NORMAL) self.messagebox.delete(1.0,tk.END) self.messagebox.insert(tk.END, '>> ') self.messagebox.config(state=tk.DISABLED) for item in self.r2map_panel.r2map_tree.get_children(): for child in self.r2map_panel.r2map_tree.children(item): self.r2map_panel.r2map_tree.delete(child) self.r2map_panel.r2map_tree.delete(item) if event == 'OpenProject': self.messagebox.config(state=tk.NORMAL) self.messagebox.delete(1.0,tk.END) self.messagebox.insert(tk.END, '>> Open ') self.messagebox.insert(tk.END, self.project_panel.get_project_name()) self.messagebox.insert(tk.END, ' project.') self.messagebox.config(state=tk.DISABLED) for item in self.r2map_panel.r2map_tree.get_children(): for child in self.r2map_panel.r2map_tree.children(item): self.r2map_panel.r2map_tree.delete(child) self.r2map_panel.r2map_tree.delete(item) for key in sorted(self.project_panel.dicom_files): id = self.r2map_panel.r2map_tree.insert('', 'end', text=key) i=0 for item in self.project_panel.dicom_files[key]: self.r2map_panel.r2map_tree.insert(id, 'end', text=str(i), values=(item.SeriesNumber, item.SeriesDescription, item.EchoTime)) i += 1 if self.project_panel.meta_data['r2maps']: self.r2mapsID = self.r2map_panel.r2map_tree.insert('', 'end', text='R2maps') for key in self.project_panel.meta_data['r2maps']: i=0 id = self.r2map_panel.r2map_tree.insert(self.r2mapsID, 'end', text=key) self.r2maps = np.load(self.project_panel.project_dir+'/r2map'+'key') for item in self.project_panel.meta_data['r2maps'][key]: self.r2map_panel.r2map_tree.insert(id, 'end', text = str(i)) i += 1 if event == 'ReadDicom': self.messagebox.config(state=tk.NORMAL) self.messagebox.insert(tk.END, '\n>> Read dicom files.') self.messagebox.config(state=tk.DISABLED) if name == 'projectinfo.treepanel': project_tree = self.project_panel.get_project_tree() if event == '<<TreeviewSelect>>': selection = project_tree.selection()[0] parent = project_tree.parent(selection) print(name, event, selection, parent) if parent: self.dicom_img.set_images(self.project_panel.get_dicom_images()[parent]) self.dicom_img.set_indexOfImg(int(project_tree.item(project_tree.selection())['text'])) self.dicom_img.show_images() else: self.dicom_img.set_images(self.project_panel.get_dicom_images()[selection]) if event == 'delete_item': temp = {} for item in project_tree.get_children(): key = project_tree.item(item)['text'] temp[key] = self.project_panel.get_dicom_path()[key] self.project_panel.set_meta_data('dicom_dict', temp) if name == 'projectinfo.projectinfo': if event == 'Save': self.messagebox.config(state=tk.NORMAL) self.messagebox.insert(tk.END, '\n>> Save project data.') self.messagebox.config(state=tk.DISABLED) if event == 'Modify': self.messagebox.config(state=tk.NORMAL) self.messagebox.insert(tk.END, '\n>> Modify project data.') self.messagebox.config(state=tk.DISABLED) if name == 'r2projectpanel': if event == '<<TreeviewSelect>>': selection = self.r2map_panel.r2map_tree.selection()[0] parent = self.r2map_panel.r2map_tree.parent(selection) if parent: self.r2map_dicom_img.set_images(self.project_panel.get_dicom_images()[parent]) self.r2map_dicom_img.set_indexOfImg(int(self.r2map_panel.r2map_tree.item(self.r2map_panel.r2map_tree.selection())['text'])) self.r2map_dicom_img.show_images() else: self.r2map_dicom_img.set_images(self.project_panel.get_dicom_images()[selection]) if name == 'r2mappanel': if event == 'r2mapping': if self.r2map_panel.map_algoritm.get() == 'Polyfit': self.r2maping() if name == 'r2map_dicom_frame': if event == '<DrawRectangle>': print('OK') points = self.r2map_dicom_img.getRectanglePoints() self.r2map_panel.lx0.set(int(points[0])) self.r2map_panel.lx1.set(int(points[1])) self.r2map_panel.ly0.set(int(points[2])) self.r2map_panel.ly1.set(int(points[3])) if name == 'calibrationpanel': if event == 'calr2maptree.<<TreeviewSelect>>': selection = self.calibration_panel.r2maptree.selection()[0] self.calibration_r2map_img.set_images(self.r2maps) if event == 'addvalue': x0 = int(self.calibration_r2map_img.x0) x1 = int(self.calibration_r2map_img.x1) y0 = int(self.calibration_r2map_img.y0) y1 = int(self.calibration_r2map_img.y1) print(x0,x1,y1,y0) id = self.calibration_r2map_img.indexOfImg average = np.median(self.r2maps[id, y1:y0,x0:x1]) print(self.r2maps[id, x0:x1,y1:y0]) #sd = np.std(self.r2maps[id, x0:x1,y1:y0]) print('Mean = '+str(average)) #print('Std = '+str(sd)) i = len(self.r2value) self.calibration_panel.spreadsheet.cells['R2'+str(i+1)].insert(0, average) self.r2value.append(average) self.calibration_dosemap_img.set_images(self.r2maps[:, x1:x0,y0:y1]) self.calibration_dosemap_img.set_indexOfImg(id) self.calibration_dosemap_img.show_images() def r2maping(self): self.pixels = [] self.te = [] for item in self.r2map_panel.r2map_tree.get_children(): self.pixels.append(self.project_panel.dicom_images[item]) self.te.append(self.project_panel.project_tree.item(item)['text']) print(self.te) row = np.shape(self.pixels[0][0])[0] column = np.shape(self.pixels[0][0])[0] nSlice = np.shape(self.pixels[0])[0] print('Slice ' + str(nSlice)) r2maps = [] sigma = [] images = self.pixels col0 = int(self.r2map_dicom_img.x0) col1 = int(self.r2map_dicom_img.x1) row0 = int(self.r2map_dicom_img.y0) row1 = int(self.r2map_dicom_img.y1) for s in range(0,nSlice): print(s) r2map = np.zeros((row, column)) for i in range(row0,row1): for j in range(col0,col1): temp = [] for item in self.pixels: if item[s][i,j]!=0: temp.append(np.log(item[s][i,j])) else: temp.append(0) slope = np.polyfit(self.te, temp,1) r2map[i,j] = -slope[0] r2maps.append(r2map) #self.project_panel.meta_data['r2maps']['key'] = self.project_panel.project_dir+'/r2map'+'key' #with open(self.project_panel.project_dir+'/'+self.project_panel.project_name+'.dat', 'wb') as outfile: # pickle.dump(self.project_panel.meta_data, outfile, protocol=pickle.HIGHEST_PROTOCOL) self.r2maps = np.array(r2maps) np.save(self.project_panel.project_dir+'/r2map'+'key', self.r2maps) self.r2map_img.set_images(self.r2maps) self.r2map_img.show_images() n = len(self.calibration_panel.r2maptree.get_children()) self.calibration_panel.r2maptree.insert('', 'end', text=str(n+1), value=('', 'Polyfit'))