############################################################################ # # 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. # ############################################################################ """ Usage: python """ import gdcm import sys filename = sys.argv[1] tmpfile = "/tmp/philips_rescaled.dcm" # Need to access some private tags, read the file : reader = gdcm.Reader() reader.SetFileName( filename ) if not reader.Read(): sys.exit(1) ds = reader.GetFile().GetDataSet() #print ds # (2005,1409) DS 4 0.0 # (2005,140a) DS 16 1.52283272283272 # (2005,0014) LO 26 Philips MR Imaging DD 005 tag1 = gdcm.PrivateTag(0x2005,0x09,"Philips MR Imaging DD 005") tag2 = gdcm.PrivateTag(0x2005,0x0a,"Philips MR Imaging DD 005") print tag1 print tag2 # make sure to do a copy, we want the private tag to remain # otherwise gdcm gives us a reference el1 = gdcm.DataElement( ds.GetDataElement( tag1 ) ) print el1 el2 = gdcm.DataElement( ds.GetDataElement( tag2 ) ) print el2 # (0028,1052) DS [-1000] # 6, 1 RescaleIntercept # (0028,1053) DS [1] # 2, 1 RescaleSlope el1.SetTag( gdcm.Tag(0x0028,0x1052) ) el2.SetTag( gdcm.Tag(0x0028,0x1053) ) ds.Insert( el1 ) ds.Insert( el2 ) w = gdcm.Writer() w.SetCheckFileMetaInformation( False ) w.SetFileName( tmpfile ) w.SetFile( reader.GetFile() ) if not w.Write(): sys.exit(1) print "success"