Menu

[r134]: / trunk / htdocs / examples / mri_with_eeg.py  Maximize  Restore  History

Download this file

59 lines (49 with data), 1.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# note, this is currentl *very slow*. I'm working on improving the
# efficiency of pcolor. If you want to run this example and your
# computer is not very fast, I suggest you grab a cup of coffee while
# it runs
from matplotlib.matlab import *
from matplotlib.lines import Line2D
# I use if 1 to break up the different regions of code visually
if 1: # load the data
# data are 256x256 16 bit integers
dfile = 'data/s1045.ima'
im = fromstring(file(dfile, 'rb').read(), Int16).astype(Float)
im.shape = 256, 256
# flip upside down
im = array([im[i] for i in arange(255,-1,-1)])
if 1: # plot the MRI in pcolor
subplot(221)
pcolor(im, shading='flat')
axis('off')
if 1: # plot the histogram of MRI intensity
subplot(222)
im.shape = 256*256,
im = take(im, nonzero(im)) # ignore the background
im = im/(2.0**15) # normalize
hist(im, 100)
set(gca(), 'xticks', [-1, -.5, 0, .5, 1])
set(gca(), 'yticks', [])
xlabel('intensity')
ylabel('MRI density')
if 1: # plot the EEG
# load the data
numSamples, numRows = 800,4
data = fromstring(file('data/eeg.dat', 'rb').read(), Float)
data.shape = numSamples, numRows
t = arange(numSamples)/float(numSamples)*10.0
ticklocs = []
ax = subplot(212)
for i in range(numRows):
thisLine = Line2D(ax.dpi, ax.bbox, t, data[:,i]-data[0,i],
transx=ax.xaxis.transData, transy=ax.yaxis.transData)
thisLine.set_vertical_offset(3*i)
ax.add_line(thisLine)
ticklocs.append(3*i)
set(gca(), 'xticks', arange(10))
set(gca(), 'yticks', ticklocs)
set(gca(), 'yticklabels', ['PG3', 'PG5', 'PG7', 'PG9'])
#set(gca(), 'ylim', [0, 20])
xlabel('time (s)')
savefig('mri_with_eeg')
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.