16 This example shows how one can use the gdcm.Anonymizer in 'dumb' mode.
17 This class becomes really handy when one knows which particular tag to fill in.
21 python DumbAnonymizer.py gdcmData/012345.002.050.dcm out.dcm
28 THERALYS_ORG_ROOT =
"1.3.6.1.4.17434"
32 (0x0012,0x0010):(
"Value",
"MySponsorName"),
33 (0x0012,0x0020):(
"Value",
"MyProtocolID"),
34 (0x0012,0x0021):(
"Value",
"MyProtocolName"),
35 (0x0012,0x0062):(
"Value",
"YES"),
36 (0x0012,0x0063):(
"Value",
"MyDeidentificationMethod"),
41 (0x0008,0x0018):(
"Method",
"GenerateMSOPId"),
42 (0x0010,0x0010):(
"Method",
"GetSponsorInitials"),
43 (0x0010,0x0020):(
"Method",
"GetSponsorId"),
44 (0x0012,0x0030):(
"Method",
"GetSiteId"),
45 (0x0012,0x0031):(
"Method",
"GetSiteName"),
46 (0x0012,0x0040):(
"Method",
"GetSponsorId"),
47 (0x0012,0x0050):(
"Method",
"GetTPId"),
48 (0x0018,0x0022):(
"Method",
"KeepIfExist"),
49 (0x0018,0x1315):(
"Method",
"KeepIfExist"),
50 (0x0020,0x000d):(
"Method",
"GenerateStudyId"),
51 (0x0020,0x000e):(
"Method",
"GenerateSeriesId"),
52 (0x0020,0x1002):(
"Method",
"GetNumberOfFrames"),
53 (0x0020,0x0020):(
"Method",
"GetPatientOrientation"),
55 (0x0012,0x0051):(
"Patient Field",
"Type Examen"),
56 (0x0018,0x1250):(
"Sequence Field",
"Receive Coil"),
57 (0x0018,0x0088):(
"Sequence Field",
"Spacing Between Slice"),
58 (0x0018,0x0095):(
"Sequence Field",
"Pixel Bandwidth"),
59 (0x0018,0x0082):(
"Sequence Field",
"Invertion Time"),
68 self.studyuid = generator.Generate()
69 if not self.seriesuid:
70 self.seriesuid = generator.Generate()
71 def GetSponsorInitials(self):
73 def GenerateStudyId(self):
75 def GenerateSeriesId(self):
78 def GenerateMSOPId(self):
80 return generator.Generate()
83 def GetSiteName(self):
85 def GetSponsorId(self):
90 if __name__ ==
"__main__":
96 filename = sys.argv[1]
97 r.SetFileName( filename )
98 if not r.Read(): sys.exit(1)
104 ano.SetFile( r.GetFile() )
105 ano.RemoveGroupLength()
106 for tag,rule
in tag_rules.items():
107 if rule[0] ==
'Value':
109 ano.Replace(
gdcm.Tag( tag[0], tag[1] ), rule[1] )
110 elif rule[0] ==
'Method':
114 if hasattr(obj, methodname):
115 _member = getattr(obj, methodname)
117 ano.Replace(
gdcm.Tag( tag[0], tag[1] ), result )
119 print "Problem with: ", methodname
121 outfilename = sys.argv[2]
122 w.SetFileName( outfilename )
123 w.SetFile( ano.GetFile() )
124 if not w.Write(): sys.exit(1)