GDCM 3.2.1

RemovePrivateTags.py
1
14
15"""
16 Usage:
17
18 python RemovePrivateTags.py input.dcm output.dcm
19"""
20
21 import sys
22 import gdcm
23
24
25 if __name__ == "__main__":
26
27 file1 = sys.argv[1]
28 file2 = sys.argv[2]
29
30 # Instantiate the reader.
31 r = gdcm.Reader()
32 r.SetFileName( file1 )
33 if not r.Read():
34 sys.exit(1)
35
36 # Remove private tags
37 ano = gdcm.Anonymizer()
38 ano.SetFile( r.GetFile() )
39 if not ano.RemovePrivateTags():
40 sys.exit(1)
41
42 # Write DICOM file
43 w = gdcm.Writer()
44 w.SetFile( ano.GetFile() )
45 #w.CheckFileMetaInformationOff() # Do not attempt to check meta header
46 w.SetFileName( file2 )
47 if not w.Write():
48 sys.exit(1)
49
50 # It is usually a good idea to exit the script with an error, as gdcm does not remove partial (incorrect) DICOM file
51 # (application level)
gdcm::Anonymizer
Anonymizer.
Definition gdcmAnonymizer.h:78
gdcm::Reader
Reader ala DOM (Document Object Model)
Definition gdcmReader.h:54
gdcm::Writer
Writer ala DOM (Document Object Model)
Definition gdcmWriter.h:49