]> Creatis software - gdcm.git/blob - gdcmPython/demo/vtkGdcmWriter.py.in
To allow testsuite go on.
[gdcm.git] / gdcmPython / demo / vtkGdcmWriter.py.in
1 import sys
2 import os.path
3 from gdcmConfigDemo import *
4 from gdcmPython.vtk import *
5 from vtkpython import *
6
7 def PrintUse():
8    print ""
9    print "Use :"
10    print "-----"
11    print "%s <fileName>" % sys.argv[0]
12    print "   fileName : path to the DICOM file to see"
13    print ""
14    print ""
15
16 # Get the file names
17 try:
18    fileName = sys.argv[1]
19 except IndexError:
20    fileName = os.path.join(GDCM_DATA_ROOT, "test.acr")
21    if( not os.path.isfile(fileName) ):
22       fileName=os.path.join(os.path.split(sys.argv[0])[0],"test.acr")
23
24 if( not os.path.isfile(fileName) ):
25    PrintUse()
26    sys.exit(1)
27
28 # read the image
29 reader = vtkGdcmReader()
30 reader.SetFileName(fileName)
31 reader.Update()
32
33 # write the image
34 writer = vtkGdcmWriter()
35 writer.SetInput(reader.GetOutput())
36 writer.SetFileName("outputPy.dcm")
37 writer.Write()
38
39 # re-read the image
40 reader2 = vtkGdcmReader()
41 reader2.SetFileName("outputPy.dcm")
42 reader2.Update()
43
44 # show the image
45 viewer = vtkImageViewer()
46 viewer.SetInput(reader2.GetOutput())
47 rng = reader.GetOutput().GetScalarRange()
48 viewer.SetColorWindow(rng[1] - rng[0])
49 viewer.SetColorLevel(0.5 * (rng[1] + rng[0]))
50
51 dim = reader.GetOutput().GetDimensions()
52 viewer.SetSize(dim[0],dim[1])
53 if(dim[2] != 1):
54    # For multiframe dicom, take a snapshot of the center slice (+/- 1)
55    viewer.SetZSlice(dim[2] / 2)
56 else:
57    viewer.SetZSlice(0)
58 viewer.Render()
59
60 # sys.stdin.read(1)
61