Reading and extracting images from a large DICOM file

Hi everyone,
I’m a beginner with ITK.
I need to extract all the images from a very large (about 3 GB) .dcm file and save them as .bmp files.
To do this, I’m trying to read the file as shown in the examples. However, the program is killed by the system during the
operation, since this requires a very large amount of memory.
Are there any C++ examples of how I can read such files without completely loading the entire DICOM file into the reader object ?

Have you tried turning on virtual memory (swap file)? Maybe @mihail.isakov has some DICOM-specific suggestions?

hi @dzenanz Thank you for feedback.
My question is not how to prevent the killing of application.
The question is how to read the data in a way that requires less memory.
What it looks now. The more images there are inside one DICOM file, the more memory is required. The question is whether it is possible to process (to read) this data like a stream, such that previously read and converted images are removed from memory.

You could take a look at ProcessImageChunks example. I don’t think that DICOM IO in ITK supports streaming. For file formats which do, take a look at StreamingImageIOBase’s inheritance diagram. Additionally, MetaIO supports streaming for uncompressed images.

Conclusion: I don’t think you can partially read DICOMs using ITK. You might be able to do that using DICOM-specific functionality.

  1. It might be possible to stream into an ITK filter. For example, the gdcm stream read write test:
    suggests that it might be possible.

Perhaps try running that test on your file. The command-line for running that test is given in the cmakelists.txt file in the test directory

If that works, perhaps look at other streaming examples.

  1. Another option, as suggested by @dzenanz, is to access GDCM directly.

This post might help with that…(remove the loop if your data isn’t multi-frame)…

1 Like

If GDCM supports streaming, you could combine ProcessImageChunks with this example.

Thank you guys!
I’ll investigate your advice and examples tomorrow.