验证 DICOM 文件
我必须从文件夹中选择所有有效的 DICOM 文件。我可以递归地从具有 *.DCM 扩展名的文件夹中选取所有文件。但任何带有 *.DCM 的文件也会被拾取,并且此类文件不是有效的 DICOM 文件。
什么是最好的方法。
我想读取文件的几个字节并进行验证。
或者
任何其他方法或我们拥有的任何其他可验证的 EXE。
谢谢你, Harsha
编辑:问题的解决方案: 我最终使用了dcmftest.exe进行验证。希望我走在正确的轨道上。 -哈沙
I have to pick all valid DICOM Files from folder. I can recursively pick all the files from the folder which have *.DCM extension. But any file with *.DCM also picked up and such file is not valid DICOM File.
What is best way.
I thought of reading few byte of the file and validating.
Or
Any Other Method or any other EXEs we have which validates.
Thank you,
Harsha
Edit: Solution for the problem:
I finally used the dcmftest.exe for verification. Hope I am on right track.
-Harsha
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您想要识别 DICOM 文件,而不是验证。有很大的区别。验证意味着(至少!)其 SOP 类所需的所有标签都存在。
识别很容易,因为 DICOM 文件必须在偏移量 0x80 处包含文本
DICM
,因此标签从文件的偏移量 0x84 开始。请注意,有时仅存储序列化数据集(从文件偏移量 0 处的标签组 8 开始),这些更难以识别,但不是标准的。
编辑:作为示例,请考虑 RAR 存档。它很容易识别,因为它以
Rar!
开头。然而,为了确保它是有效的 RAR 存档,您必须解压缩所有文件并检查它们的 CRC,而这只能由 RAR 本身完成(而且速度很慢)。You want to recognize DICOM files, not to validate. There is big difference. Validation means (at least!) that all the tags required for its SOP class are present.
Recognition is easy, as the DICOM file has to contain text
DICM
at the offset 0x80, so that tags start at the offset 0x84 of file.Note that sometimes only the serialized dataset is stored (starting with tag group 8 at file offset 0), and these are more difficult to recognize, but are not standard.
EDIT: As an example, consider a RAR archive. It's easy to recognize, because it starts with
Rar!
. However, to be sure that it's a valid RAR archive, you have to decompress all the files and check their CRCs, and this is something that could be done only by RAR itself (and it's slow).我知道这个问题已经得到解答,但我有类似的要求,所以我想出了一些扩展方法来做到这一点。适用于文件、文件流、内存流和通用流。仅读取验证文件类型所需的特定 4 个字节。非常高效,我能够在几秒钟内运行完数千个文件。
C#
VB.NET
I know this has been answered already but I had a similar requirement, so I whipped up some extension methods to do exactly that. Works on Files, FileStreams, MemoryStreams and generic Streams. Only reads the specific 4 bytes needed to validate the filetype. Extremely efficient, I was able to run through thousands of files within seconds.
C#
VB.NET
仅供参考,具有 .dcm 扩展名的文件并不是真正合法的 DICOM,尽管出于遗留原因,最好编写程序来接受它们(但您不应该在应用程序导出的 DICOM 文件上放置 3 个字符的文件扩展名)。根据 DICOM 标准中有关媒体交换的部分,“不得使用 ISO 9660 文件扩展名”。此外,除了标准第 10 部分和第 12 部分中描述的特殊 DICOMDIR 文件之外,不应从文件名或目录结构推断任何语义。
ruslik的答案为您提供了识别 DICOM 文件的正确方法。如果文件前导码中的指定位置有 DICM,则它是 DICOM 文件。否则就不是了。
FYI, files with a .dcm extension are not really legitimate DICOM, although for legacy reasons it's a good idea to write your programs to accept them anyway (but you shouldn't put 3 character filename extensions on DICOM files exported by your application). According to the part of the DICOM standard regarding media exchange, "The ISO 9660 File Name Extension shall not be used." Furthermore, no semantics should be inferred from filenames or directory structure except for the special DICOMDIR file described in parts 10 and 12 of the standard.
ruslik's answer gives you the correct way to recognize DICOM files. If it has DICM in the designated location in the file preamble, then it's a DICOM file. Otherwise, it's not.
请注意:检查“DICM”前导码将仅检查文件是否为 DICOM v3 文件。
以前版本的 DICOM 没有序言。可以查看的 100% 有效 DICOM 文件,具有所有必要的 DICOM 标签等,并且可以导入到 DICOM 节点中,没有前导码。
我正在与 OFFIS 核实,看看 DCMCHECK 的许可版本是否也有此限制,但我还没有收到他们的回复。
Be aware : checking the preamble for "DICM" will only check to see if the file is a DICOM v3 file.
Previous versions of DICOM did not have the preamble. 100% valid DICOM files that can be viewed, with all the requisite DICOM tags etc, and are importable into a DICOM node, don't have the preamble.
I'm checking with OFFIS to see if the licensed version of DCMCHECK also has this constraint or not, but I've not heard back from them yet.
考虑到不同 IOD 中存在不同的强制和可选标签,验证 DICOM 文件并不是一件容易的任务。我认为最好使用现有的解决方案来做到这一点。您可以查看来自 DCMTK 的 DCMCHECK 来执行此操作。
Validating a DICOM file is not as easy task considering the different mandatory and optional tags present in different IODs. I think it is better to use an existing solution to do this. You can take a look at DCMCHECK from DCMTK to do this.