1

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?

Jaime
  • 5,770
  • 4
  • 23
  • 50
  • Are you looking for products or trying to write code? – john elemans Dec 10 '15 at 17:21
  • I am trying to write a C++ code to retrieve the DIOCM data. – acetechcare Dec 11 '15 at 04:05
  • Have you looked at the DICOM spec? I have you looked at some of the tools available? – john elemans Dec 11 '15 at 04:10
  • Yes. I already have gone through the DICOM PS3.18 2015c - Web Services. I am new to http communication. So my doubt is purely related to parsing the multi part byte stream to required data by removing the content boundary information. – acetechcare Dec 11 '15 at 10:52
  • Well I can't find much information for you. I saw a posting by someone else who struggled with it until he got a tip to write the file to disc and then just parse the disc file as a standard dicom file. Sorry I can't be more helpful. – john elemans Dec 11 '15 at 17:32

1 Answers1

2

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()
user252046
  • 399
  • 2
  • 11