Mri Viewer
'''This is a simple mri viewer the mri is read using the img module with the read function from mri import img nim=img.read()' import numpy t=viewmri.plotit(numpy.flipud(nim.data))''' import numpy from numpy import shape from pylab import figure, show, connect, disconnect, cm, axis, subplots_adjust ##from mri import img ##nim=img.read() ##x=nim.data.transpose() class IndexTracker: def __init__(self, data, ax1, ax2, ax3): self.ax1 = ax1 ax1.set_title('Sagital') self.ax2 = ax2 ax2.set_title('Coronal') self.ax3 = ax3 ax3.set_title('Axial') self.data = data rows,cols,self.slices1 = data.shape rows,self.slices2,cols = data.shape self.slices3,rows,cols = data.shape self.ind1 = self.slices1/2 self.ind2 = self.slices2/2 self.ind3 = self.slices3/2 self.im1 = ax1.imshow(self.data[:,:,self.ind1], cmap=cm.gray) self.im2 = ax2.imshow(self.data[:,self.ind2,:], cmap=cm.gray) self.im3 = ax3.imshow(self.data[self.ind3,:,:], cmap=cm.gray) self.update1() def onscroll(self, event): if event.inaxes == self.ax1: if event.button=='up': self.ind1 = numpy.clip(self.ind1+1, 0, self.slices1-1) else: self.ind1 = numpy.clip(self.ind1-1, 0, self.slices1-1) self.update() ## self.im1.set_data(self.data[:,:,self.ind1]) ## self.im1.axes.figure.canvas.draw() if event.inaxes == self.ax2: if event.button=='up': self.ind2 = numpy.clip(self.ind2+1, 0, self.slices2-1) else: self.ind2 = numpy.clip(self.ind2-1, 0, self.slices2-1) self.update() ## self.im2.set_data(self.data[:,self.ind2,:]) ## self.im2.axes.figure.canvas.draw() if event.inaxes == self.ax3: if event.button=='up': self.ind3 = numpy.clip(self.ind3+1, 0, self.slices3-1) else: self.ind3 = numpy.clip(self.ind3-1, 0, self.slices3-1) self.update() ## self.im3.set_data(self.data[self.ind3,:,:]) ## self.im3.axes.figure.canvas.draw() def update(self): self.update1();self.update2();self.update3() def update1(self): self.im1.set_data(self.data[:,:,self.ind1]) self.im1.axes.figure.canvas.draw() ## self.ax1.axhline(y=self.ind1, xmin=0, xmax=1) ## axvline(x=.5, ymin=0, ymax=1) def update2(self): self.im2.set_data(self.data[:,self.ind2,:]) self.im2.axes.figure.canvas.draw() def update3(self): self.im3.set_data(self.data[self.ind3,:,:]) self.im3.axes.figure.canvas.draw() def click(self,event): print 'you clicked', event.xdata, event.ydata ## print 'you pressed button ', event.button ## print 'your on slice ', self.ind1, event.inaxes self.events=event if event.inaxes == self.ax1: ## print 'you clicked on image 1' self.ind2=int(event.xdata) self.ind3=int(event.ydata) print 'slice ', self.ind3 self.update() if event.inaxes == self.ax2: ## print 'you clicked on image 2' self.ind1=int(event.xdata) self.ind3=int(event.ydata) print 'slice ', self.ind1 self.update() if event.inaxes == self.ax3: ## print 'you clicked on image 3' self.ind1=int(event.xdata) self.ind2=int(event.ydata) print 'slice ', self.ind2 self.update() return event def plotit(data): "mri=img.decimate(nim, 5)" "ex. slice.plot(mri)" fig = figure() subplots_adjust(left=0, bottom=0,right=1, top=.85,wspace=.1, hspace=.1) ax1 = fig.add_subplot(221);axis('off') ax2 = fig.add_subplot(222);axis('off') ax3 = fig.add_subplot(223);axis('off') tracker = IndexTracker(data, ax1, ax2, ax3) fig.canvas.mpl_connect('scroll_event', tracker.onscroll) connect('button_press_event', tracker.click) show() return tracker
This is a simple mri viewer the mri is read using the img module with the read function
from mri import img
nim=img.read()'
data=nim.data()'
t=viewmri.plotit(numpy.flipud(nim.data))'''
page_revision: 16, last_edited: 1221511338|%e %b %Y, %H:%M %Z (%O ago)





