首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pydicom私有标记显示为“UN”

Pydicom私有标记显示为“UN”
EN

Stack Overflow用户
提问于 2020-02-12 17:29:37
回答 1查看 871关注 0票数 3

当我读到一个字典文件时,所有的私人标签都会出现在“UN”的虚拟现实中,而不是它们应该是什么。

代码语言:javascript
复制
import pydicom
filename = 'H:\Fuji.dcm'
ds = pydicom.dcmread(filename)
print(ds)

给出的输出为:

代码语言:javascript
复制
...
(0009, 0010) Private Creator                     LO: 'FDMS 1.0'
(0009, 1005) [Image UID]                         UN: b'\x1d\xa6h\x12\x08\x07pZ\x0f9\x0e\xc2'
(0009, 1006) [Route Image UID]                   UN: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
(0009, 1008) [Image Display Information Version  UN: b'\x00\x00\x00\x00'
(0009, 1009) [Patient Information Version No.]   UN: b'\x00\x00\x00\x00'
(0009, 100c) [Film UID]                          UN: b'\x1d\xa6h\x12\x08\x07pZ\x0f9\x0e\xc2'
(0009, 1010) [Exposure Unit Type Code]           UN: b'F3'
(0009, 1080) [Kanji Hospital Name]               UN: None
(0009, 1090) [Distribution Code]                 UN: b'MAINPACS'
(0009, 10f0) [Blackening Process Flag]           UN: b'01'
(0009, 10f1) [Processing Information Flag]       UN: b'0001'
(0009, 10f2) Private tag data                    UN: b'01'
(0009, 10f3) Private tag data                    UN: b'01'
(0009, 10f4) Private tag data                    UN: b'01'
...

如果我尝试用以下方式手动添加它们,这种情况不会改变:

代码语言:javascript
复制
pydicom.datadict.add_private_dict_entries('FDMS 1.0', 
                                          {0x00090005:('OW','1','Image UID'),
                                           0x00090006:('OW','1','Route Image UID'),
                                           0x00090008:('UL','1','Image Display Information Version No.'),
                                           0x00090009:('UL','1','Patient Information Version No.'),
                                           0x0009000c:('OW','1','Film UID'),
                                           0x00090010:('CS','1','Exposure Unit Type Code'),
                                           0x00090080:('LO','1','Kanji Hospital Name'),
                                           0x00090090:('ST','1','Distribution Code'),
                                           0x000900F0:('CS','1','Blackening Process Flag'),
                                           0x000900F1:('ST','1','Processing Information Flag'),
                                           0x000900F2:('CS','1','Normalization Flag'),
                                           0x000900F3:('CS','1','Tone characteristic'),
                                           0x000900F4:('CS','1','Window Value Fixed Flag'),
                                           })
print(ds)

它正确地提取了丢失标签的描述,但仍然不会改变联合国的VR:

代码语言:javascript
复制
...
(0009, 0010) Private Creator                     LO: 'FDMS 1.0'
(0009, 1005) [Image UID]                         UN: b'\x1d\xa6h\x12\x08\x07pZ\x0f9\x0e\xc2'
(0009, 1006) [Route Image UID]                   UN: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
(0009, 1008) [Image Display Information Version  UN: b'\x00\x00\x00\x00'
(0009, 1009) [Patient Information Version No.]   UN: b'\x00\x00\x00\x00'
(0009, 100c) [Film UID]                          UN: b'\x1d\xa6h\x12\x08\x07pZ\x0f9\x0e\xc2'
(0009, 1010) [Exposure Unit Type Code]           UN: b'F3'
(0009, 1080) [Kanji Hospital Name]               UN: None
(0009, 1090) [Distribution Code]                 UN: b'MAINPACS'
(0009, 10f0) [Blackening Process Flag]           UN: b'01'
(0009, 10f1) [Processing Information Flag]       UN: b'0001'
(0009, 10f2) [Normalization Flag]                UN: b'01'
(0009, 10f3) [Tone characteristic]               UN: b'01'
(0009, 10f4) [Window Value Fixed Flag]           UN: b'01'
...

在我尝试过的所有临床dicom文件中,这似乎都是一致的行为,无论是在读取dicom文件之前还是之后添加条目都没有什么区别。

我在本例中使用的文件如下:

-6SsKK/view?usp=共享

谢谢你能提供的任何帮助。

未来任何人的

我将以下来自MrBean不来梅的代码与来自pydicom.values.convert_values的一些代码组合起来,以获得以下函数以代替dcmread:

代码语言:javascript
复制
def dcmread_convert_private(filename):
    ds = pydicom.dcmread(filename)
    for e in ds:
        if e.tag.is_private and e.VR == 'UN':
            try:
                index = (e.tag.element >> 12) - 1
                if index >= 0:
                    private_creators = ds.private_creators(e.tag.group)
                    if len(private_creators) > index:
                        private_creator = private_creators[index]
                        e.VR = pydicom.datadict.private_dictionary_VR(e.tag, private_creator)
                        # Following code taken from pydicom.values.convert_value
                        if e.value:
                            if isinstance(pydicom.values.converters[e.VR], tuple):
                                converter, num_format = pydicom.values.converters[e.VR]
                            else:
                                converter = pydicom.values.converters[e.VR]
                                num_format = None
                            byte_string = e.value
                            is_little_endian = ds.is_little_endian
                            is_implicit_VR = ds.is_implicit_VR
                            if e.VR in pydicom.charset.text_VRs or e.VR == 'PN':
                                e.value = converter(byte_string)
                            elif e.VR != "SQ":
                                e.value = converter(byte_string,
                                                  is_little_endian,
                                                  num_format)
                            else:
                                e.value = convert_SQ(byte_string,
                                                   is_implicit_VR,
                                                   is_little_endian,
                                                   e.value)
            except KeyError:
                pass
    return ds

我只在几个dicom文件上测试过这一点,所以可能有些情况没有得到正确的处理。如果我遇到任何问题,我会记得回到这里,并在我修复后更新它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-12 19:20:28

问题是标签已经写入文件中为UN,并保存为显式VR。我猜想它最初被写为隐式VR,后来被转换为显式VR --在此转换过程中,所有未知的私有标记都将UN作为VR。

在pydicom中不处理私有标记注册和文件重读的情况-- UN的情况只对非私有标记进行处理。所以你在这里运气不好。

我认为这是可以添加到pydicom中的东西--我不确定这是否会是性能上的问题,但是提出一个相应的问题是有意义的(您可以自己来做,或者如果您愿意的话我可以这样做)。

下面是一个快速而肮脏的实现,用于在读取数据集中的标记后转换它:

代码语言:javascript
复制
from pydicom import dcmread
from pydicom.datadict import private_dictionary_VR

ds = dcmread('xxx.dcm'))
for e in ds:
    if e.tag.is_private and e.VR == 'UN':
        try:
            index = (e.tag.element >> 12) - 1
            if index >= 0:
                private_creators = ds.private_creators(e.tag.group)
                if len(private_creators) > index:
                    private_creator = private_creators[index]
                    e.VR = private_dictionary_VR(e.tag, private_creator)
        except KeyError:
            pass
print(ds)

更新:

这是在pydicom问题中处理的,并且可以从pydicom2.2发行版中获得。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60194005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档