1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
############################################################################
#
# Program: GDCM (Grassroots DICOM). A DICOM library
#
# Copyright (c) 2006-2011 Mathieu Malaterre
# All rights reserved.
# See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the above copyright notice for more information.
#
############################################################################
import vtkgdcm
import vtk
from vtk.util.misc import vtkGetDataRoot
#print vtkGetDataRoot()
VTK_DATA_ROOT = vtkGetDataRoot()
print(VTK_DATA_ROOT)
v16 = vtk.vtkVolume16Reader()
v16.SetDataDimensions(64, 64)
v16.SetDataByteOrderToLittleEndian()
v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter")
v16.SetImageRange(1, 93)
v16.SetDataSpacing(3.2, 3.2, 1.5)
#v16.Update()
#
#print v16.GetOutput()
w = vtkgdcm.vtkGDCMImageWriter()
w.SetInputConnection( v16.GetOutputPort() )
w.SetFileDimensionality( 3 )
w.SetFileName( "sc.dcm" )
w.Write()
# Now pretend this is an MR Image Storage:
# Since image is 3D it should default to the new Enhance MR Image Storage:
med = w.GetMedicalImageProperties()
med.SetModality( "MR" )
w.SetFileName( "mr.dcm" )
w.Write()
|