diff --git a/invesalius/control.py b/invesalius/control.py index e31d2f7..a3ee546 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -19,8 +19,8 @@ import math import os import plistlib -import tempfile +import numpy import wx.lib.pubsub as ps import constants as const @@ -386,12 +386,16 @@ class Controller(): proj.SetAcquisitionModality("MRI") #TODO: Verify if all Analyse are in AXIAL orientation - if not header['orient']: + # To get Z, X, Y (used by InVesaliu), not X, Y, Z + matrix, matrix_filename = utils.analyze2mmap(imagedata) + if header['orient'] == 0: proj.original_orientation = const.AXIAL elif header['orient'] == 1: proj.original_orientation = const.CORONAL elif header['orient'] == 2: proj.original_orientation = const.SAGITAL + else: + proj.original_orientation = const.SAGITAL proj.threshold_range = (header['glmin'], header['glmax']) @@ -399,7 +403,8 @@ class Controller(): proj.level = (0.5 * (proj.threshold_range[1] + proj.threshold_range[0])) self.Slice = sl.Slice() - self.Slice.matrix = imagedata.get_data().swapaxes(0, 2) + self.Slice.matrix = matrix + self.Slice.matrix_filename = matrix_filename self.Slice.window_level = proj.level self.Slice.window_width = proj.window diff --git a/invesalius/data/imagedata_utils.py b/invesalius/data/imagedata_utils.py index 40fd708..17e2811 100644 --- a/invesalius/data/imagedata_utils.py +++ b/invesalius/data/imagedata_utils.py @@ -507,6 +507,45 @@ def dcm2memmap(files, slice_size, orientation): return matrix, scalar_range, temp_file +def analyze2mmap(analyze): + data = analyze.get_data() + header = analyze.get_header() + temp_file = tempfile.mktemp() + + # Sagital + if header['orient'] == 2: + print "Orientation Sagital" + shape = tuple([data.shape[i] for i in (1, 2, 0)]) + matrix = numpy.memmap(temp_file, mode='w+', dtype=data.dtype, shape=shape) + for n, slice in enumerate(data): + matrix[:,:, n] = slice + + # Coronal + elif header['orient'] == 1: + print "Orientation coronal" + shape = tuple([data.shape[i] for i in (1, 0, 2)]) + matrix = numpy.memmap(temp_file, mode='w+', dtype=data.dtype, shape=shape) + for n, slice in enumerate(data): + matrix[:,n,:] = slice + + # AXIAL + elif header['orient'] == 0: + print "no orientation" + shape = tuple([data.shape[i] for i in (0, 1, 2)]) + matrix = numpy.memmap(temp_file, mode='w+', dtype=data.dtype, shape=shape) + for n, slice in enumerate(data): + matrix[n] = slice + + else: + print "Orientation Sagital" + shape = tuple([data.shape[i] for i in (1, 2, 0)]) + matrix = numpy.memmap(temp_file, mode='w+', dtype=data.dtype, shape=shape) + for n, slice in enumerate(data): + matrix[:,:, n] = slice + + matrix.flush() + return matrix, temp_file + def to_vtk(n_array, spacing, slice_number, orientation): try: dz, dy, dx = n_array.shape -- libgit2 0.21.2