From a4a270ea5c31d76a240c108a46d71ea37e578b17 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 22 Aug 2012 16:55:07 -0400 Subject: [PATCH] Add the python script used to view the 3D input/results. --- util/view-mri-data.py | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 util/view-mri-data.py 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() -- 2.44.2