]> gitweb.michael.orlitzky.com - spline3.git/blob - util/view-mri-data.py
spline3.cabal: bump version to 1.0.2
[spline3.git] / util / view-mri-data.py
1 #!/usr/bin/python2
2
3 """
4 Display volumetric data from the Stanford Volume Data Archive. The
5 data (layers) are expected to be concatenated together.
6 """
7
8 from mayavi import mlab
9 import os
10 import sys
11
12 def usage():
13 binary = sys.argv[0]
14 print "Usage:", binary, "<data file>"
15
16 if len(sys.argv) < 2:
17 usage()
18 raise SystemExit
19
20
21 def cube_root(n):
22 """
23 For integers, this probably even works.
24 """
25 for x in range(0,n+1):
26 if x**3 == n:
27 return x
28
29 return None
30
31
32 # Read the data in a numpy 3D array
33 import numpy as np
34 data = np.fromfile(sys.argv[1], dtype='>u2')
35
36 original_data_length = 7143424
37 multiplier = cube_root(len(data) / original_data_length)
38 data.shape = (109*multiplier, 256*multiplier, 256*multiplier)
39 data = data.T
40
41 # Display the data
42 mlab.figure(bgcolor=(0, 0, 0), size=(1000, 1000))
43
44 src = mlab.pipeline.scalar_field(data)
45
46 # Our data is not equally spaced in all directions:
47 src.spacing = [1, 1, 1.5]
48 src.update_image_data = True
49 v = mlab.pipeline.volume(src, vmax=2500, vmin=1400)
50 mlab.show()