Path: news.mathworks.com!not-for-mail
From: Jeff Mather <jeff.mather@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Out of memory- Try to read dicom file
Date: Thu, 04 Jan 2007 13:48:32 -0500
Organization: The MathWorks, Inc.
Lines: 54
Message-ID: <enji60$253$1@fred.mathworks.com>
References: <ef4915a.-1@webcrossing.raydaftYaTP> <ef4915a.0@webcrossing.raydaftYaTP> <ef4915a.1@webcrossing.raydaftYaTP> <ef4915a.2@webcrossing.raydaftYaTP>
NNTP-Posting-Host: matherj.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1167936512 2211 144.212.219.188 (4 Jan 2007 18:48:32 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Jan 2007 18:48:32 +0000 (UTC)
User-Agent: Thunderbird 1.5.0.8 (Windows/20061025)
In-Reply-To: <ef4915a.2@webcrossing.raydaftYaTP>
Xref: news.mathworks.com comp.soft-sys.matlab:386043



merdim wrote:
 >>
 >> Here is the error massage:
 >>
 >> ??? Out of memory. Type HELP MEMORY for your options.
 >>
 >> Error in ==> dicomread>processRawPixels at 657
 >> X = reshape(metadata.InstanceData(1:numPixels), metadata.Columns,
 >> ...
 >>
 >> Error in ==> dicomread>newDicomread at 222
 >> X = processRawPixels(metadata);
 >>
 >> Error in ==> dicomread at 82
 >> [X, map, alpha, overlays] = newDicomread(msgname, varargin{:});
 >> I use matlab version of 7.0.4.365 (R14) Service Pack 2
 >>

Ofek Shilon wrote:
> what happens if you replace lines 657-658 with :
> 
> X = metadata.InstanceData; % temp duplicity
> rmfield(metadata,'InstanceData'); % remove duplicity
> X=reshape(X, metadata.Columns, metadata.Rows, 1, ...
>           metadata.NumberOfFrames);


It's likely that you need some combination of the original 
implementation and Ofek's suggestion.  In particular, the code may need 
to index into InstanceData.  (Certain naughty "DICOM" file writers put 
too much data into the pixel data.)

It's entirely possible that the combination of indexing into the array 
and performing the reshape is overwhelming your system's memory.  The 
indexing makes a copy of the data and reshaping makes at least one more. 
  Add that to the original InstanceData field and you're talking about 
258*3 MB or 258*4 MB required for that line.  Consider splitting the 
line like this:

   if (numel(metadata.InstanceData) > numPixels)
       metadata.InstanceData((numPixels+1):end) = [];
   elseif (numel(metadata.InstanceData) < numPixels)
       error('Not enough pixel data')
   end

   X = reshape(metadata.InstanceData, ...
               metadata.Columns, ...
               metadata.Rows, ...
               1, ...
               metadata.NumberOfFrames);

Jeff Mather
Image Processing Group
The MathWorks, Inc.