1
1
"""Utilities for working with DICOM datasets
2
2
"""
3
3
4
- from nibabel .casting import asstr
5
-
6
4
7
5
def find_private_section (dcm_data , group_no , creator ):
8
6
"""Return start element in group `group_no` given creator name `creator`
@@ -19,10 +17,10 @@ def find_private_section(dcm_data, group_no, creator):
19
17
``tag``, ``VR``, ``value``
20
18
group_no : int
21
19
Group number in which to search
22
- creator : str or bytes or regex
23
- Name of section - e.g. 'SIEMENS CSA HEADER' - or regex to search for
20
+ creator : bytes or regex
21
+ Name of section - e.g. b 'SIEMENS CSA HEADER' - or regex to search for
24
22
section name. Regex used via ``creator.search(element_value)`` where
25
- ``element_value`` is the value of the data element.
23
+ ``element_value`` is the decoded value of the data element.
26
24
27
25
Returns
28
26
-------
@@ -31,15 +29,17 @@ def find_private_section(dcm_data, group_no, creator):
31
29
"""
32
30
if hasattr (creator , 'search' ):
33
31
match_func = creator .search
34
- else : # assume string / bytes
35
- match_func = asstr (creator ).__eq__
32
+ else : # assume bytes
33
+ creator = creator .decode ('latin-1' )
34
+ match_func = creator .__eq__
36
35
# Group elements assumed ordered by tag (groupno, elno)
37
36
for element in dcm_data .group_dataset (group_no ):
38
37
elno = element .tag .elem
39
38
if elno > 0xFF :
40
39
break
41
40
if element .VR not in ('LO' , 'OB' ):
42
41
continue
43
- if match_func (asstr (element .value )):
42
+ val = element .value .decode ('latin-1' )
43
+ if match_func (val ):
44
44
return elno * 0x100
45
45
return None
0 commit comments