From: Michael Orlitzky Date: Wed, 22 Aug 2012 20:55:07 +0000 (-0400) Subject: Add the python script used to view the 3D input/results. X-Git-Tag: 0.0.1~35 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=a4a270ea5c31d76a240c108a46d71ea37e578b17;p=spline3.git Add the python script used to view the 3D input/results. --- diff --git a/util/view-mri-data.py b/util/view-mri-data.py new file mode 100755 index 0000000..96fbfa5 --- /dev/null +++ b/util/view-mri-data.py @@ -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, "" + +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()