如何使用 MergeCom 库修改 DICOM 文件的前导码?
How to modify the preamble of a DICOM file using MergeCom library?
我需要使用 C++ 修改 DICOM 文件的序言。我知道我可以使用 MergeCom 库来做到这一点。但是我对这个库很陌生,以前没用过。我打开了 user manual,但它太长了,我需要时间才能找到我需要的东西。
谁能指导我朝这个方向发展,或者给我一个简单的代码片段来做这件事。
我建议不要使用 DICOM 工具包(如 Merge)来执行此操作。
DICOM PS 3.10,第 7.1 章
The File Meta Information includes identifying information on the encapsulated Data Set. This header consists of a 128 byte File
Preamble, followed by a 4 byte DICOM prefix, followed by the File Meta Elements shown in Table 7.1-1. This header shall be present
in every DICOM file.
所以序言总是 132 字节长,并且总是从文件的第一个字节开始。使用原始文件访问方法(如 fopen、fwrite)将二进制数据块放入文件比 "convincing" DICOM 工具包将错误的前导码写入文件要容易得多。
无论如何,使用 mergecom 工具包是可能的:
MC_STATUS MC_Set_File_Preamble(
int FileID,
char* Preamble
)
其中 FileId 是 MC_Open_File 返回的合并句柄。
P.S.: 我很少使用MergeCom 用户手册。我使用参考手册搜索 "Preamble" 很快就得到了结果。
我同意@kritzel_sw 在其他回答中的第一个建议。如果只限于写序言,不涉及加载数据集或读取元素等任何其他功能,那么使用工具包就太过分了。
以下是specifications关于序言的内容:
The File Meta Information includes identifying information on the encapsulated Data Set. This header consists of a 128 byte File Preamble, followed by a 4 byte DICOM prefix, followed by the File Meta Elements shown in Table 7.1-1. This header shall be present in every DICOM file.
和
If the File Preamble is not used by an Application Profile or a specific implementation, all 128 bytes shall be set to 00H. This is intended to facilitate the recognition that the Preamble is used when all 128 bytes are not set as specified above.
The File Preamble may for example contain information enabling a multi-media application to randomly access images stored in a DICOM Data Set. The same file can be accessed in two ways: by a multi-media application using the preamble and by a DICOM Application that ignores the preamble.
另外,下面是一个 image 可能有助于更好地理解这个概念:
The first part, the file header, consists of a 128-byte file preamble followed by a 4-byte prefix. This approach is very common in many other image standards such as TIFF that you may have already seen/used. The 4-byte prefix consists of the uppercase characters 'DICM' (note, it is not “DICOM”, but “DICM”).
如您所见,Preamble是DICOM文件头的开始部分。您可以使用您的编程语言轻松添加它,而无需使用任何工具包。
查看 this 问题,该问题讨论了使用 C# 阅读 序言。希望对你有所帮助。
我需要使用 C++ 修改 DICOM 文件的序言。我知道我可以使用 MergeCom 库来做到这一点。但是我对这个库很陌生,以前没用过。我打开了 user manual,但它太长了,我需要时间才能找到我需要的东西。
谁能指导我朝这个方向发展,或者给我一个简单的代码片段来做这件事。
我建议不要使用 DICOM 工具包(如 Merge)来执行此操作。
DICOM PS 3.10,第 7.1 章
The File Meta Information includes identifying information on the encapsulated Data Set. This header consists of a 128 byte File Preamble, followed by a 4 byte DICOM prefix, followed by the File Meta Elements shown in Table 7.1-1. This header shall be present in every DICOM file.
所以序言总是 132 字节长,并且总是从文件的第一个字节开始。使用原始文件访问方法(如 fopen、fwrite)将二进制数据块放入文件比 "convincing" DICOM 工具包将错误的前导码写入文件要容易得多。
无论如何,使用 mergecom 工具包是可能的:
MC_STATUS MC_Set_File_Preamble(
int FileID,
char* Preamble
)
其中 FileId 是 MC_Open_File 返回的合并句柄。
P.S.: 我很少使用MergeCom 用户手册。我使用参考手册搜索 "Preamble" 很快就得到了结果。
我同意@kritzel_sw 在其他回答中的第一个建议。如果只限于写序言,不涉及加载数据集或读取元素等任何其他功能,那么使用工具包就太过分了。
以下是specifications关于序言的内容:
The File Meta Information includes identifying information on the encapsulated Data Set. This header consists of a 128 byte File Preamble, followed by a 4 byte DICOM prefix, followed by the File Meta Elements shown in Table 7.1-1. This header shall be present in every DICOM file.
和
If the File Preamble is not used by an Application Profile or a specific implementation, all 128 bytes shall be set to 00H. This is intended to facilitate the recognition that the Preamble is used when all 128 bytes are not set as specified above.
The File Preamble may for example contain information enabling a multi-media application to randomly access images stored in a DICOM Data Set. The same file can be accessed in two ways: by a multi-media application using the preamble and by a DICOM Application that ignores the preamble.
另外,下面是一个 image 可能有助于更好地理解这个概念:
The first part, the file header, consists of a 128-byte file preamble followed by a 4-byte prefix. This approach is very common in many other image standards such as TIFF that you may have already seen/used. The 4-byte prefix consists of the uppercase characters 'DICM' (note, it is not “DICOM”, but “DICM”).
如您所见,Preamble是DICOM文件头的开始部分。您可以使用您的编程语言轻松添加它,而无需使用任何工具包。
查看 this 问题,该问题讨论了使用 C# 阅读 序言。希望对你有所帮助。