c++dicom

How to modify the preamble of a DICOM file?


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.

How can I modify the preamble of a DICOM file using MergeCom?


Solution

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