def interpolate(self): # elec_coord = geodesic3D_hybrid(A_vox, B_vox, D_vox, C_vox, 8, 8, mask_data) elec_coord = interpol(A_vox, B_vox, C_vox, 8, 8) snap_coords = elec_snap(elec_coord, ct_data) for point in snap_coords: ct_data[point[0]-2:point[0]+2, point[1]-2:point[1]+2, point[2]-2:point[2]+2] = 5000 mip = ct2mip(ct_data, 1, theta, phi) a.imshow(mip) canvas.show()
def on_release(self, event): # On release of button, final MIP is calculated and press data is reset xpress, ypress = self.press dx = event.xdata - xpress dy = event.ydata - ypress theta = -dx * 0.5 phi = dy * 0.5 mip = ct2mip(ct_data, 1, theta, phi) a.imshow(mip) canvas.show() self.press = None
def on_motion(self, event): # From mouse motion event, detect displacement of mouse and adjust/show MIP accordingly try: xpress, ypress = self.press dx = event.xdata - xpress dy = event.ydata - ypress theta = -dx * 0.5 phi = dy * 0.5 mip = ct2mip(ct_data, 1, theta, phi) a.imshow(mip) canvas.show() except Exception: pass
def test_patients(self,patient_id,theta,phi): """ """ try: # Load the segmentation file seg_filename = '%s/%s_unburied_electrode_seg.nii.gz'%(DATA_DIR, patient_id) img = nib.load(path.expanduser(seg_filename)) ct_data = img.get_data() mip_start = time.clock() mip = ct2mip(ct_data, 1, theta, phi) print "Making MIP took: %s s"%(time.clock()-mip_start) plt.imshow(mip) plt.show() return True except Exception, e: print str(e) return False
def resett(self): mip = ct2mip(ct_data, 1, 0, 0) a.imshow(mip) canvas.show()
def plot_mip(self): # Initialize theta and phi (MIP camera angle variables) and generate MIP global theta global phi theta = 0 phi = 0 mip = ct2mip(ct_data, 1, theta, phi) global wind wind = 50 # Initialize main figure window that will contain MIP f1 = Figure(figsize=(3,3), dpi=100) global a a = f1.add_subplot(111) a.xaxis.set_visible(False) a.yaxis.set_visible(False) a.imshow(mip) # Initialize first orthogonal figure window f2 = Figure(figsize=(1,1), dpi=100) global b b = f2.add_subplot(111) b.xaxis.set_visible(False) b.yaxis.set_visible(False) b.imshow(np.zeros((wind*2,wind*2))) # Initialize second orthogonal figure window f3 = Figure(figsize=(1,1), dpi=100) global c c = f3.add_subplot(111) c.xaxis.set_visible(False) c.yaxis.set_visible(False) c.imshow(np.zeros((wind*2,wind*2))) # Initialize third orthogonal figure window f4 = Figure(figsize=(1,1), dpi=100) global d d = f4.add_subplot(111) d.xaxis.set_visible(False) d.yaxis.set_visible(False) d.imshow(np.zeros((wind*2,wind*2))) # Incorporate figures into canvas widgets in Tkinter global canvas canvas = FigureCanvasTkAgg(f1, self) canvas.show() canvas.get_tk_widget().grid(row=4, rowspan=3, column=1, columnspan=3, sticky=tk.N+tk.E+tk.S+tk.W) global canvas2 canvas2 = FigureCanvasTkAgg(f2, self) canvas2.show() canvas2.get_tk_widget().grid(row=4, rowspan=1, column=4, columnspan=1, sticky=tk.N+tk.E+tk.S+tk.W) global canvas3 canvas3 = FigureCanvasTkAgg(f3, self) canvas3.show() canvas3.get_tk_widget().grid(row=5, rowspan=1, column=4, columnspan=1, sticky=tk.N+tk.E+tk.S+tk.W) global canvas4 canvas4 = FigureCanvasTkAgg(f4, self) canvas4.show() canvas4.get_tk_widget().grid(row=6, rowspan=1, column=4, columnspan=1, sticky=tk.N+tk.E+tk.S+tk.W) # Specify which grid spaces should expand for x in xrange(4): self.columnconfigure(x, weight=1) for y in xrange(4,8): self.rowconfigure(y, weight=1)