Multipart WADO-RS dicom data parsing

961 views Asked by At

I am using WADO-RS with Content-Type: application/dicom. After successful execution of request, I got a byte stream that contains some header information and DICOM data in Multipart format. How can I parse the actual DICOM data from it using C++ code?

1

There are 1 answers

1
user252046 On

Each part of the multipart file is a dicom instance. Each part contains a content-length field, I decode the length from the content field. The dicom file starts 4 bytes after the end of content length field. The length will tell you where the dicom file ends. below is a python snippet:

for dicm in re.finditer(b'Content-Length:', mime_bytes_msg):

    content_length_index = dicm.end() + 1
    content_length = ''

    dicom_file = open('%s/%s_%d.dcm' % (output_path, dicom_prefix, instance_number), 'wb')
    instance_number += 1
    while mime_bytes_msg[content_length_index:content_length_index + 1].decode('utf-8').isdigit():
        content_length += mime_bytes_msg[content_length_index:content_length_index + 1].decode('utf-8')
        content_length_index += 1

    dicom_start_index = content_length_index + 4
    dicom_file.write(mime_bytes_msg[dicom_start_index:dicom_start_index + int(content_length)])

    dicom_file.close()