How to modify the preamble of a DICOM file using MergeCom library? [closed]

倾然丶 夕夏残阳落幕 提交于 2020-12-13 03:44:16

问题


I need to modify the preamble of a DICOM file using C++. I know I can do this using MergeCom library. However I am very new to this library and haven't used this before. I opened the user manual but it's too extensive and is taking me time to get what I need.

Can someone guide me in that direction or give me a simple code snippet that does this thing.


回答1:


I would advise against using a DICOM toolkit (like Merge) to do that.

DICOM PS 3.10, Chapter 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.

So the preamble is always 132 bytes long and always beginning with the first byte of the file. Using raw file access methods (like fopen, fwrite) to put a binary data block into the file would be much easier than "convincing" a DICOM toolkit to write a wrong preamble to the file.

Anyway, it is possible with the mergecom toolkit:

MC_STATUS MC_Set_File_Preamble(
int FileID,
char* Preamble
)

Where FileId is the merge handle as returned by MC_Open_File.

P.S.: I rarely use the MergeCom user manual. I use the reference manual a search for "Preamble" gave me the result quite quickly.




回答2:


I agree with first recommendation from @kritzel_sw in other answer. If it is just limited to writing a preamble and does not involve any other features like loading dataset or reading elements etc., using toolkit is overkill.

Following is what specifications say about preamble:

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.

and

  1. 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.

  2. 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.

Also, following is an image that may help understanding the concept better:

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”).

As you can see, Preamble is the starting part of header of DICOM file. You can easily add it using your programming language without using any toolkit.

Have a look at this question which discusses reading the preamble with C#. Hope that will help you.



来源:https://stackoverflow.com/questions/58336075/how-to-modify-the-preamble-of-a-dicom-file-using-mergecom-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!