]> gitweb.michael.orlitzky.com - spline3.git/commitdiff
Add the python script used to view the 3D input/results.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 22 Aug 2012 20:55:07 +0000 (16:55 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 22 Aug 2012 20:55:07 +0000 (16:55 -0400)
util/view-mri-data.py [new file with mode: 0755]

diff --git a/util/view-mri-data.py b/util/view-mri-data.py
new file mode 100755 (executable)
index 0000000..96fbfa5
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/python2
+
+"""
+Display volumetric data from the Stanford Volume Data Archive. The
+data (layers) are expected to be concatenated together.
+"""
+
+from mayavi import mlab
+import os
+import sys
+
+def usage():
+    binary = sys.argv[0]
+    print "Usage:", binary, "<data file>"
+
+if len(sys.argv) < 2:
+    usage()
+    raise SystemExit
+
+
+def cube_root(n):
+    """
+    For integers, this probably even works.
+    """
+    for x in range(0,n+1):
+        if x**3 == n:
+            return x
+
+    return None
+
+
+# Read the data in a numpy 3D array
+import numpy as np
+data = np.fromfile(sys.argv[1], dtype='>u2')
+
+original_data_length = 7143424
+multiplier = cube_root(len(data) / original_data_length)
+data.shape = (109*multiplier, 256*multiplier, 256*multiplier)
+data = data.T
+
+# Display the data
+mlab.figure(bgcolor=(0, 0, 0), size=(1000, 1000))
+
+src = mlab.pipeline.scalar_field(data)
+
+# Our data is not equally spaced in all directions:
+src.spacing = [1, 1, 1.5]
+src.update_image_data = True
+v = mlab.pipeline.volume(src, vmax=2500, vmin=1400)
+mlab.show()