Why do I get a memory error when I attempt to read a single frame from a large DICOM file?

2 views (last 30 days)
I have a DICOM file that has a large number of frames. I want to read this file into MATLAB one frame at a time, but I cannot because of memory issues.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Oct 2010
This enhancement has been incorporated in Release 2010b (R2010b). For previous product releases, read below for any possible workarounds:
This is a limitation of the Image Processing Toolbox DICOM functionality. The DICOMREAD function attempts to load all the frames of the file before discarding the frames that are not requested. That is the reason for the memory error; MATLAB cannot store the entire contents of this file at the same time.
The following is one possible workaround. Attached is a function that will parse frames of some DICOM files, but does not work in the general case. The following are assumptions that were made that must be respected for this program to work correctly on DICOM files:
  • The image must have just 8- or 16-bits/sample.
  • The image samples must span their data container.
  • The image must be grayscale.
  • The pixels must be uncompressed.
  • The file must have explicit value representation ("explicit VR").
  • The pixel data endianness and the machine's endianness must match.
  • The pixel data must have a known length.
Also this function must be placed in the same directory as the built-in DICOMREAD command. To install this function, download the attached file to the current MATLAB working directory. Then run the following code:
movefile('read_dicom_frame.m',fileparts(which('dicomread.m')))
rehash toolboxcache
Now it should be possible to extract data from your file, 'myfile.DCM', as follows:
frm=read_dicom_frame('myfile.DCM', 1);
imagesc(frm);
Note that if any of the above assumptions are violated for data other than the example file, necessary modifications must be made to the "read_dicom_frame.m" file. Also note that if the solution above does not work, another possibility would be for to use another computer (probably a 64-bit machine) with a large amount of memory that could load the entire file using the built-in DICOM functions.

More Answers (0)

Categories

Find more on DICOM Format in Help Center and File Exchange

Products


Release

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!