Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Array of Images Running out of memory
Date: Tue, 6 Jan 2009 13:16:02 +0000 (UTC)
Organization: Queen's University
Lines: 17
Message-ID: <gjvlii$sdh$1@fred.mathworks.com>
References: <gjupaq$jeu$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1231247762 29105 172.30.248.38 (6 Jan 2009 13:16:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 6 Jan 2009 13:16:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 943450
Xref: news.mathworks.com comp.soft-sys.matlab:510011


Hi,

I think it should be,
totalFiles = sequenceEndNo - sequenceStartNo + 1;

By underestimating the total number of files, the preallocated array isn't quite big enough and adding the last image results in a new, larger array being created - as far as I know the original array cannot be expanded, so about twice as much memory is needed (at least temporarily).

If you still have memory problems, you could consider using the single rather than double data type, which should halve the memory requirements.  You would preallocate using
a = zeros(144, 512, totalFiles, 'single');

A 144x512x400 single array would be about 112.5 MB, while the double array would be 225 MB.  You might not need the extra precision of using double.

Depending upon how the images are stored, you also might be able to skip the call to mat2gray.

All the best,

Pete