Skip to content

Commit e1f8c19

Browse files
General BisonGeneral Bison
authored andcommitted
not longer as dirty, working!, more white-list-tags
1 parent 9005696 commit e1f8c19

4 files changed

Lines changed: 53 additions & 11 deletions

File tree

core.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import os
2626
import dicom
27-
27+
import random
2828

2929
def isDicom(fullpath):
3030
"""
@@ -114,24 +114,44 @@ def anonymize_byWhitelist(whitelist, filename, newfilename):
114114
for ar in whitelist:
115115
for subAr in ar:
116116
nwhitelist.append(str(subAr).replace("'", ''))
117+
#print nwhitelist
117118

118119
# Load the current dicom file to get tag- and valuelist
119120
dataset = dicom.read_file(filename)
120121

121122
# write delete nonwhitelist tag values into datalist
122123
#dataset.walk(tagbased_callback)
123124

124-
for dt in dataset.keys():
125+
for dt in dataset:
125126
#print type(dt)
126-
if str(dt) in nwhitelist:
127+
#print dt, dt.__dict__
128+
#print dt.tag
129+
if str(dt.tag) in nwhitelist:
127130
pass
128131
#print 'keep:', str(dt)
129132
#print dataset[dt]
133+
#insatnce number
134+
#series number
130135
else:
131-
print 'del:', str(dt), '|', dataset[dt].value
132-
dataset[dt].value = ''
133-
print dataset[dt]
134-
136+
if 'value' in dt.__dict__:
137+
print 'del:', dt
138+
print 'val:', dataset.value
139+
dataset.value = ''
140+
else:
141+
print 'hard reset:', dt
142+
tmpType = type(dt._value)
143+
if tmpType is str:
144+
dt._value = ''
145+
elif tmpType is int or tmpType is float:
146+
dt._value = 0
147+
elif tmpType is list:
148+
dt._value = []
149+
elif str(tmpType) == "<class 'dicom.UID.UID'>":
150+
dt._value = "0"
151+
#print 'UID cant be reset', tmpType
152+
else:
153+
print 'unknown type:', '#'+str(tmpType)+'#'
154+
dt._value = ""
135155
#for whitelisttag in whitelist:
136156
# if str(data_element.tag) != str(whitelisttag):
137157
# cnt+=1

lists/tags_to_hold/tags_hold_always.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
0020,0020 patient orientation
1111
0020,0032 image position
1212
0020,0037 image orientation
13-
0020,ff
14-
0028,ff
13+
#0020,ff
14+
#0028,ff
15+
1516
# forgotten!
1617
0028,0102 High Bit
1718
7fe0,0010 Pixel Data
@@ -32,10 +33,17 @@
3233
0028,0000 Group Length
3334
0020,0000 Group Length
3435
0018,0000 Group Length
36+
0008,0000 Group Length
37+
7fe0,0000 Group Length
3538
0028,0030 Pixel Spacing
3639
0028,1054 Rescale Type
3740
0028,1053 Rescale Slope
3841
0028,1052 Rescale Intercept
42+
#0009,0011 some sort of list
43+
0008,0012 Instance Creation Date
44+
0008,0013 Instance Creation Time
45+
0028,0101 Bits Stored
46+
3947
# not that important
4048
0028,1051 Window Width
4149
0028,1050 Window Center
@@ -50,4 +58,5 @@
5058
0008,0104 Code Meaning
5159
0008,0102 Coding Scheme Designator
5260
0008,0100 Code Value
53-
0008,0016 SOP Class UID
61+
0008,0016 SOP Class UID
62+
#0008,0018 SOP Instance UID

lists/tags_to_hold/tags_hold_for_scientific.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#
44
#hold for scientific
55
#
6-
#0010,0030 birthday
6+
0010,0030 birthday
77
0010,0040 sex

shell_show_tags.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,24 @@ def getValMaxLen(val):
2424

2525
dataset = dicom.read_file(filePath)
2626

27+
for k, val in dataset.iteritems():
28+
print k
29+
print val
30+
print 10*'#'
31+
32+
33+
exit(0)
2734
for dt in dataset.keys():
2835
print 'key: ', dt
36+
#if isinstance([], dt):
37+
# print 'cant show list!'
38+
#else:
39+
#print 'foo:', type(dt.value), dt.value
2940
try:
3041
print 'dataset:', dataset[dt]
3142
print 'value: ', getValMaxLen(dataset[dt].value)
3243
except Exception as ex:
44+
print 'ERROR:'
45+
print 'typ:', type(dt)
3346
print ex
3447
print 10*'#'

0 commit comments

Comments
 (0)