From a2b84c22268dd01bd5b30f39f34c209863284e29 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Tue, 24 Feb 2015 09:53:15 +0000 Subject: [PATCH] Handle NIFTI images which have the wrong number of dimensions in their header --- fsl/data/image.py | 24 +++++++++++++++++++-- fsl/fslview/gl/textures.py | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/fsl/data/image.py b/fsl/data/image.py index e1a839dc0..5e8df1193 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -190,8 +190,28 @@ class Image(props.HasProperties): be called if the ``loadData`` parameter passed to :meth:`__init__` was ``False``. """ - self.data = self.nibImage.get_data() - self.data.flags.writeable = False + + data = self.nibImage.get_data() + + # Squeeze out empty dimensions, as + # 3D image can sometimes be listed + # as having 4 or more dimensions + shape = data.shape + + for i in reversed(range(len(shape))): + if shape[i - 1] == 1: + data = data.squeeze(axis=i - 1) + + data.flags.writeable = False + + log.debug('Loaded image data ({}) - original ' + 'shape {}, squeezed shape {}'.format( + self.name, + shape, + data.shape)) + + self.data = data + def applyChange(self, offset, newVals, vol=None): diff --git a/fsl/fslview/gl/textures.py b/fsl/fslview/gl/textures.py index ee84237ad..9737c2aaf 100644 --- a/fsl/fslview/gl/textures.py +++ b/fsl/fslview/gl/textures.py @@ -354,6 +354,49 @@ class ImageTexture(object): voxValXform = transform.scaleOffsetXform(scale, offset) + if log.getEffectiveLevel() == logging.DEBUG: + + if texDtype == gl.GL_UNSIGNED_BYTE: + sTexDtype = 'GL_UNSIGNED_BYTE' + elif texDtype == gl.GL_UNSIGNED_SHORT: + sTexDtype = 'GL_UNSIGNED_SHORT' + + if texFmt == gl.GL_LUMINANCE: + sTexFmt = 'GL_LUMINANCE' + elif texFmt == gl.GL_LUMINANCE_ALPHA: + sTexFmt = 'GL_LUMINANCE_ALPHA' + elif texFmt == gl.GL_RGB: + sTexFmt = 'GL_RGB' + elif texFmt == gl.GL_RGBA: + sTexFmt = 'GL_RGBA' + + if intFmt == gl.GL_LUMINANCE8: + sIntFmt = 'GL_LUMINANCE8' + elif intFmt == gl.GL_LUMINANCE16: + sIntFmt = 'GL_LUMINANCE16' + elif intFmt == gl.GL_LUMINANCE8_ALPHA8: + sIntFmt = 'GL_LUMINANCE8_ALPHA8' + elif intFmt == gl.GL_LUMINANCE16_ALPHA16: + sIntFmt = 'GL_LUMINANCE16_ALPHA16' + elif intFmt == gl.GL_RGB8: + sIntFmt = 'GL_RGB8' + elif intFmt == gl.GL_RGB16: + sIntFmt = 'GL_RGB16' + elif intFmt == gl.GL_RGBA8: + sIntFmt = 'GL_RGBA8' + elif intFmt == gl.GL_RGBA16: + sIntFmt = 'GL_RGBA16' + + log.debug('Image texture ({}) is to be stored as {}/{}/{} ' + '(normalised: {} - scale {}, offset {})'.format( + self.image, + sTexDtype, + sTexFmt, + sIntFmt, + self.normalise, + scale, + offset)) + return texFmt, intFmt, texDtype, voxValXform -- GitLab