GDCM: PhilipsPrivateRescaleInterceptSlope.py

GDCM 3.2.7

PhilipsPrivateRescaleInterceptSlope.py
1
14
15"""
16Usage:
17
18 python
19"""
20
21import gdcm
22import sys
23
24filename = sys.argv[1]
25tmpfile = "/tmp/philips_rescaled.dcm"
26
27
28# Need to access some private tags, read the file :
29reader = gdcm.Reader()
30reader.SetFileName( filename )
31if not reader.Read():
32 sys.exit(1)
33
34ds = 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
41tag1 = gdcm.PrivateTag(0x2005,0x09,"Philips MR Imaging DD 005")
42tag2 = gdcm.PrivateTag(0x2005,0x0a,"Philips MR Imaging DD 005")
43print tag1
44print tag2
45
46# make sure to do a copy, we want the private tag to remain
47# otherwise gdcm gives us a reference
48el1 = gdcm.DataElement( ds.GetDataElement( tag1 ) )
49print el1
50el2 = gdcm.DataElement( ds.GetDataElement( tag2 ) )
51print el2
52
53# (0028,1052) DS [-1000] # 6, 1 RescaleIntercept
54# (0028,1053) DS [1] # 2, 1 RescaleSlope
55
56el1.SetTag( gdcm.Tag(0x0028,0x1052) )
57el2.SetTag( gdcm.Tag(0x0028,0x1053) )
58
59ds.Insert( el1 )
60ds.Insert( el2 )
61
62w = gdcm.Writer()
63w.SetCheckFileMetaInformation( False )
64w.SetFileName( tmpfile )
65w.SetFile( reader.GetFile() )
66if not w.Write():
67 sys.exit(1)
68
69print "success"
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::PrivateTag
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner).
Definition gdcmPrivateTag.h:39
gdcm::Reader
Reader ala DOM (Document Object Model).
Definition gdcmReader.h:54
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::Writer
Writer ala DOM (Document Object Model).
Definition gdcmWriter.h:49