From 58534ceb1e1f48178a6c81de4d6a3021ed9122c6 Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Thu, 21 Oct 2010 13:21:37 +0000 Subject: [PATCH] ENH: Ported analyze reader to new way to handle slices (using memmap). --- invesalius/control.py | 21 ++++++++++++++++++--- invesalius/data/imagedata_utils.py | 3 +-- invesalius/reader/analyze_reader.py | 37 +++---------------------------------- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index 3e4f194..92dbc06 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -383,16 +383,31 @@ class Controller(): ps.Publisher().sendMessage('End busy cursor') def CreateAnalyzeProject(self, imagedata): + header = imagedata.get_header() proj = prj.Project() proj.name = _("Untitled") proj.SetAcquisitionModality("MRI") - proj.imagedata = imagedata #TODO: Verify if all Analyse are in AXIAL orientation - proj.original_orientation = const.AXIAL - proj.threshold_range = imagedata.GetScalarRange() + + if not header['orient']: + proj.original_orientation = const.AXIAL + elif header['orient'] == 1: + proj.original_orientation = const.CORONAL + elif header['orient'] == 2: + proj.original_orientation = const.SAGITAL + + proj.threshold_range = (header['glmin'], + header['glmax']) proj.window = proj.threshold_range[1] - proj.threshold_range[0] 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.window_level = proj.level + self.Slice.window_width = proj.window + self.Slice.spacing = header.get_zooms()[:3] + def CreateDicomProject(self, imagedata, dicom): name_to_const = {"AXIAL":const.AXIAL, diff --git a/invesalius/data/imagedata_utils.py b/invesalius/data/imagedata_utils.py index c7a9190..aff6255 100644 --- a/invesalius/data/imagedata_utils.py +++ b/invesalius/data/imagedata_utils.py @@ -492,9 +492,8 @@ def dcm2memmap(files, slice_size, orientation): def to_vtk(n_array, spacing, slice_number, orientation): dy, dx = n_array.shape - n_array.shape = dx * dy - v_image = numpy_support.numpy_to_vtk(n_array) + v_image = numpy_support.numpy_to_vtk(n_array.flat) print orientation if orientation == 'AXIAL': diff --git a/invesalius/reader/analyze_reader.py b/invesalius/reader/analyze_reader.py index 2c91b74..d134904 100644 --- a/invesalius/reader/analyze_reader.py +++ b/invesalius/reader/analyze_reader.py @@ -23,43 +23,12 @@ import tempfile import vtk -from nibabel import AnalyzeHeader +from nibabel import AnalyzeImage, squeeze_image def ReadAnalyze(filename): - print "Reading analyze file:", filename + anlz = squeeze_image(AnalyzeImage.from_filename(filename)) + return anlz - # Reading info from analyze header - header_file = open(filename) - header = AnalyzeHeader.from_fileobj(header_file) - xf, yf, zf = header.get_data_shape()[:3] - data_type = header.get_data_dtype().name - pixel_spacing = header.get_zooms()[:3] - - # Mapping from numpy type to vtk type. - anlz_2_vtk_type = { - 'int16': 'SetDataScalarTypeToShort', - 'uint16': 'SetDataScalarTypeToUnsignedShort', - 'float32': 'SetDataScalarTypeToFloat' - } - - print header - - reader = vtk.vtkImageReader() - reader.SetFileName(filename[:-3] + 'img') - - # Setting the endiannes based on the analyze header. - if header.endianness == '<': - reader.SetDataByteOrderToLittleEndian() - elif header.endianness == '>': - reader.SetDataByteOrderToBigEndian() - - reader.SetFileDimensionality(3) - reader.SetDataExtent(0, xf-1, 0, yf-1, 0, zf-1) - reader.SetDataSpacing(pixel_spacing) - reader.SetHeaderSize(0) - # reader.SetTransform(transform) - getattr(reader, anlz_2_vtk_type[data_type])() - reader.Update() return reader.GetOutput() -- libgit2 0.21.2