chrisidefix / devide

Automatically exported from code.google.com/p/devide
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

sanitise orientation handling for DICOM datasets #198

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is a general issue for collecting resources and ideas concerning DICOM 
orientation.

Here's a mail from David Gobbi explaining how he copes with orientation in VTK 
(it remains problematic):
http://web.archiveorange.com/archive/v/50zHj2mfmWP4qGlyvmsA

With the two DICOMReader outputs connected to the two inputs of a CodeRunner, 
you could try something like the following to reslice the data so that X,Y 
corresponds to Right, Anterior:

{{{
# setup tab
######################
import vtk
ir = vtk.vtkImageReslice()

# execute tab
#########################
# the first two columns of the direction cosines matrix represent
# the x,y axes of the DICOM images in RAH space
# if we want to resample the images so that x,y are always RA
# the inverse should do the trick
medmeta = obj.inputs[1]
dcmatrix = vtk.vtkMatrix4x4()
dcmatrix.DeepCopy(medmeta.direction_cosines)
dcmatrix.Invert()

# convert our new cosines to something we can give the ImageReslice
cosines = [[0,0,0] for _ in range(3)]
for col in range(3):
    for row in range(3):
        cosines[col][row] = dcmatrix.GetElement(row, col)

# do it.
ir.SetResliceAxesDirectionCosines(cosines[0], cosines[1], cosines[2])
ir.SetInput(obj.inputs[0])
ir.Update()
obj.outputs[0] = ir.GetOutput()
}}}

Original issue reported on code.google.com by cpbotha on 26 May 2011 at 3:43