GDCM  2.2.6
PhilipsPrivateRescaleInterceptSlope.py
1 ############################################################################
2 #
3 # Program: GDCM (Grassroots DICOM). A DICOM library
4 #
5 # Copyright (c) 2006-2011 Mathieu Malaterre
6 # All rights reserved.
7 # See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 #
9 # This software is distributed WITHOUT ANY WARRANTY; without even
10 # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 # PURPOSE. See the above copyright notice for more information.
12 #
13 ############################################################################
14 
15 """
16 Usage:
17 
18  python
19 """
20 
21 import gdcm
22 import sys
23 
24 filename = sys.argv[1]
25 tmpfile = "/tmp/philips_rescaled.dcm"
26 
27 
28 # Need to access some private tags, read the file :
29 reader = gdcm.Reader()
30 reader.SetFileName( filename )
31 if not reader.Read():
32  sys.exit(1)
33 
34 ds = reader.GetFile().GetDataSet()
35 
36 #print ds
37 # (2005,1409) DS 4 0.0
38 # (2005,140a) DS 16 1.52283272283272
39 
40 # (2005,0014) LO 26 Philips MR Imaging DD 005
41 tag1 = gdcm.PrivateTag(0x2005,0x09,"Philips MR Imaging DD 005")
42 tag2 = gdcm.PrivateTag(0x2005,0x0a,"Philips MR Imaging DD 005")
43 print tag1
44 print tag2
45 
46 # make sure to do a copy, we want the private tag to remain
47 # otherwise gdcm gives us a reference
48 el1 = gdcm.DataElement( ds.GetDataElement( tag1 ) )
49 print el1
50 el2 = gdcm.DataElement( ds.GetDataElement( tag2 ) )
51 print el2
52 
53 # (0028,1052) DS [-1000] # 6, 1 RescaleIntercept
54 # (0028,1053) DS [1] # 2, 1 RescaleSlope
55 
56 el1.SetTag( gdcm.Tag(0x0028,0x1052) )
57 el2.SetTag( gdcm.Tag(0x0028,0x1053) )
58 
59 ds.Insert( el1 )
60 ds.Insert( el2 )
61 
62 w = gdcm.Writer()
63 w.SetCheckFileMetaInformation( False )
64 w.SetFileName( tmpfile )
65 w.SetFile( reader.GetFile() )
66 if not w.Write():
67  sys.exit(1)
68 
69 print "success"

Generated on Sat Dec 21 2013 05:56:15 for GDCM by doxygen 1.8.5
SourceForge.net Logo