From 4b09d3d9d05835a7a4829d62af524fb22f4ed8b9 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Fri, 17 Oct 2014 17:26:37 +0100 Subject: [PATCH] Experimenting with anatomical labels... --- fsl/data/image.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/fsl/data/image.py b/fsl/data/image.py index f90fe0387..e6a051314 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -26,6 +26,22 @@ import fsl.data.imagefile as imagefile log = logging.getLogger(__name__) +L2R = 0 +R2L = 1 +P2A = 2 +A2P = 3 +I2S = 4 +S2I = 5 + +orientationLabels = { + L2R : ('L', 'R'), + R2L : ('R', 'L'), + P2A : ('P', 'A'), + A2P : ('A', 'P'), + S2I : ('S', 'I'), + I2S : ('I', 'S') +} + def _loadImageFile(filename): """Given the name of an image file, loads it using nibabel. @@ -367,6 +383,17 @@ class Image(props.HasProperties): if worldp.size == 1: return float(worldp) else: return worldp + + def getOrientation(self, axis): + # the aff2axcodes returns one code for each + # axis in the image array (i.e. in voxel space), + # which denotes the real world direction + code = nib.orientations.aff2axcodes(self.nibImage.get_affine(), + ((R2L, L2R), + (A2P, P2A), + (S2I, I2S)))[axis] + return orientationLabels[code] + def _transform(self, p, a, axes): """Used by the :meth:`worldToVox` and :meth:`voxToWorld` methods. -- GitLab