GDCM: ManipulateFile.py

GDCM 3.2.8

ManipulateFile.py
1
14
15"""
16Usage:
17
18 python ManipulateFile.py input.dcm output.dcm
19
20Footnote:
21 GDCM 1.2.x would create incorrect Multiframes MR Image Storage file. Try to recover from
22 the issues to recreate a MultiframeGrayscaleByteSecondaryCaptureImageStorage file.
23 e.g:
24
25 python ManipulateFile.py Insight/Testing/Temporary/itkGDCMImageIOTest5-j2k.dcm manipulated.dcm
26"""
27
28import sys
29import gdcm
30
31if __name__ == "__main__":
32
33 file1 = sys.argv[1]
34 file2 = sys.argv[2]
35
36 r = gdcm.Reader()
37 r.SetFileName( file1 )
38 if not r.Read():
39 sys.exit(1)
40
41 ano = gdcm.Anonymizer()
42 ano.SetFile( r.GetFile() )
43 ano.RemovePrivateTags()
44 ano.Remove( gdcm.Tag(0x0032,0x1030) )
45 ano.Remove( gdcm.Tag(0x008,0x14) )
46 ano.Remove( gdcm.Tag(0x008,0x1111) )
47 ano.Remove( gdcm.Tag(0x008,0x1120) )
48 ano.Remove( gdcm.Tag(0x008,0x1140) )
49 ano.Remove( gdcm.Tag(0x10,0x21b0) )
50 ano.Empty( gdcm.Tag(0x10,0x10) )
51 ano.Empty( gdcm.Tag(0x10,0x20) )
52 ano.Empty( gdcm.Tag(0x10,0x30) )
53 ano.Empty( gdcm.Tag(0x20,0x10) )
54 ano.Empty( gdcm.Tag(0x32,0x1032) )
55 ano.Empty( gdcm.Tag(0x32,0x1033) )
56 ano.Empty( gdcm.Tag(0x40,0x241) )
57 ano.Empty( gdcm.Tag(0x40,0x254) )
58 ano.Empty( gdcm.Tag(0x40,0x253) )
59 ano.Empty( gdcm.Tag(0x40,0x1001) )
60 ano.Empty( gdcm.Tag(0x8,0x80) )
61 ano.Empty( gdcm.Tag(0x8,0x50) )
62 ano.Empty( gdcm.Tag(0x8,0x1030) )
63 ano.Empty( gdcm.Tag(0x8,0x103e) )
64 ano.Empty( gdcm.Tag(0x18,0x1030) )
65 ano.Empty( gdcm.Tag(0x38,0x300) )
66 g = gdcm.UIDGenerator()
67 ano.Replace( gdcm.Tag(0x0008,0x0018), g.Generate() )
68 ano.Replace( gdcm.Tag(0x0020,0x00d), g.Generate() )
69 ano.Replace( gdcm.Tag(0x0020,0x00e), g.Generate() )
70 ano.Replace( gdcm.Tag(0x0020,0x052), g.Generate() )
71 #ano.Replace( gdcm.Tag(0x0008,0x0016), "1.2.840.10008.5.1.4.1.1.7.2" )
72 """
73 ano.Remove( gdcm.Tag(0x0018,0x0020) ) # ScanningSequence
74 ano.Remove( gdcm.Tag(0x0018,0x0021) ) # SequenceVariant
75 ano.Remove( gdcm.Tag(0x0018,0x0022) ) # ScanOptions
76 ano.Remove( gdcm.Tag(0x0018,0x0023) ) # MRAcquisitionType
77 ano.Remove( gdcm.Tag(0x0018,0x0050) ) # SliceThickness
78 ano.Remove( gdcm.Tag(0x0018,0x0080) ) # RepetitionTime
79 ano.Remove( gdcm.Tag(0x0018,0x0081) ) # EchoTime
80 ano.Remove( gdcm.Tag(0x0018,0x0088) ) # SpacingBetweenSlices
81 ano.Remove( gdcm.Tag(0x0018,0x0091) ) # EchoTrainLength
82 ano.Remove( gdcm.Tag(0x0018,0x1164) ) # ImagerPixelSpacing
83
84 ano.Remove( gdcm.Tag(0x0020,0x0032) ) # Image Position (Patient)
85 ano.Remove( gdcm.Tag(0x0020,0x0037) ) # Image Orientation (Patient)
86 ano.Remove( gdcm.Tag(0x0020,0x0052) ) # Frame of Reference UID
87 ano.Remove( gdcm.Tag(0x0020,0x1040) ) # Position Reference Indicator
88
89 ano.Replace( gdcm.Tag(0x0028,0x0301), "NO" ) # Burned In Annotation
90
91 ano.Empty( gdcm.Tag(0x0020,0x0020) )
92
93 ano.Remove( gdcm.Tag(0x7fe0,0x0000) )
94
95 #ano.Empty( gdcm.Tag(0x0028,0x0009) ) # Frame Increment Pointer
96
97 #ano.Empty( gdcm.Tag(0x0028,0x1052) ) #<entry group="0028" element="1052" vr="DS" vm="1" name="Rescale Intercept"/>
98 #ano.Empty( gdcm.Tag(0x0028,0x1053) ) #<entry group="0028" element="1053" vr="DS" vm="1" name="Rescale Slope"/>
99 #ano.Replace( gdcm.Tag(0x0028,0x1054), "US" ) #<entry group="0028" element="1054" vr="LO" vm="1" name="Rescale Type"/>
100
101 ano.Replace( gdcm.Tag(0x2050, 0x0020), "IDENTITY")
102 """
103
104 w = gdcm.Writer()
105 w.SetFile( ano.GetFile() )
106 w.SetFileName( file2 )
107 if not w.Write():
108 sys.exit(1)
gdcm::Anonymizer
Anonymizer.
Definition gdcmAnonymizer.h:78
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::UIDGenerator
Class for generating unique UID.
Definition gdcmUIDGenerator.h:28
gdcm::Writer
Writer ala DOM (Document Object Model).
Definition gdcmWriter.h:49