<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241923</link>
    <title>MATLAB Central Newsreader - Array of Images Running out of memory</title>
    <description>Feed for thread: Array of Images Running out of memory</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 06 Jan 2009 05:14:02 -0500</pubDate>
      <title>Array of Images Running out of memory</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241923#620015</link>
      <author>Arron S</author>
      <description>I am very very new to matlab and have written my first M-file. It is functional for a test set of 38 images but my data sets are in the range of 400. (144x512)&lt;br&gt;
&lt;br&gt;
When I try to run it with a full data set I get an obvious memory error.  I realize that I am running 32bit XP and thus don't have a large enough contiguous memory for my data. But I know that others are able to get around this and I would like to know how. This should be easy to answer since I have read a lot of posts where people have arrays of a good deal of images but they did not explain how they were doing it. I looked at a few hundred file exchange files and searched this forum before I decided to post this message.  I did not find an answer that I understood.  Any help or links to topics pointing me in the right direction would be very helpful. &lt;br&gt;
&lt;br&gt;
My aim is to load about 400 images and run FRET analysis. &lt;br&gt;
Below is my code (probably not optimal, and itis currently molded for my data with no input/error checks yet) I used ReadDicom4.m by Nipun Patel to teach myself some of the basics and hence some of the variables are of the same name.&lt;br&gt;
&lt;br&gt;
Thank you in advance,&lt;br&gt;
Arron&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function a = imagestack(sequenceStartNo,sequenceEndNo, fileExtension)&lt;br&gt;
tic&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
fileCount=0;&lt;br&gt;
totalFiles = sequenceEndNo - sequenceStartNo;&lt;br&gt;
a= zeros(144,512,totalFiles);  % preallocation&lt;br&gt;
&lt;br&gt;
j=1;&lt;br&gt;
&lt;br&gt;
for i=sequenceStartNo:sequenceEndNo &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sequenceNo=num2str(i);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filename = strcat(sequenceNo,fileExtension);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;varname = imread (filename);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;varname = mat2gray(varname);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fileCount = fileCount + 1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a(:,:,j)= varname;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;j = j+1;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
toc&lt;br&gt;
display (fileCount);</description>
    </item>
    <item>
      <pubDate>Tue, 06 Jan 2009 07:15:51 -0500</pubDate>
      <title>Re: Array of Images Running out of memory</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241923#620018</link>
      <author>Nasser Abbasi</author>
      <description>&lt;br&gt;
&quot;Arron S&quot; &amp;lt;aps@uwm.edu&amp;gt; wrote in message &lt;br&gt;
news:gjupaq$jeu$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I am very very new to matlab and have written my first M-file. It is &lt;br&gt;
&amp;gt;functional for a test set of 38 images but my data sets are in the range of &lt;br&gt;
&amp;gt;400. (144x512)&lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;400*144*512*4  is only about 118 MBytes  I do not see why your PC can't &lt;br&gt;
manage this. Here is a small test on my Matlab&lt;br&gt;
&lt;br&gt;
EDU&amp;gt;&amp;gt; clear all&lt;br&gt;
EDU&amp;gt;&amp;gt; memory&lt;br&gt;
Maximum possible array:            1120 MB (1.174e+009 bytes) *&lt;br&gt;
Memory available for all arrays:   1529 MB (1.603e+009 bytes) **&lt;br&gt;
Memory used by MATLAB:              245 MB (2.573e+008 bytes)&lt;br&gt;
Physical Memory (RAM):             3327 MB (3.489e+009 bytes)&lt;br&gt;
&lt;br&gt;
*  Limited by contiguous virtual address space available.&lt;br&gt;
** Limited by virtual address space available.&lt;br&gt;
&lt;br&gt;
EDU&amp;gt;&amp;gt; A=zeros(144,512,400);&lt;br&gt;
&lt;br&gt;
EDU&amp;gt;&amp;gt; memory&lt;br&gt;
Maximum possible array:             895 MB (9.383e+008 bytes) *&lt;br&gt;
Memory available for all arrays:   1304 MB (1.367e+009 bytes) **&lt;br&gt;
Memory used by MATLAB:              470 MB (4.932e+008 bytes)&lt;br&gt;
Physical Memory (RAM):             3327 MB (3.489e+009 bytes)&lt;br&gt;
&lt;br&gt;
*  Limited by contiguous virtual address space available.&lt;br&gt;
** Limited by virtual address space available.&lt;br&gt;
EDU&amp;gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
So, you see that memory used by Matlab increased from 245 to 470, or by 225 &lt;br&gt;
MB only. So, I am not sure why you are getting the memory error.  How much &lt;br&gt;
RAM does your PC have? Why not set a break point on error, and look at the &lt;br&gt;
memory then? May be you are using memory somewhere else in the program?&lt;br&gt;
&lt;br&gt;
--Nasser </description>
    </item>
    <item>
      <pubDate>Tue, 06 Jan 2009 13:16:02 -0500</pubDate>
      <title>Re: Array of Images Running out of memory</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241923#620065</link>
      <author>Pete </author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I think it should be,&lt;br&gt;
totalFiles = sequenceEndNo - sequenceStartNo + 1;&lt;br&gt;
&lt;br&gt;
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).&lt;br&gt;
&lt;br&gt;
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&lt;br&gt;
a = zeros(144, 512, totalFiles, 'single');&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Depending upon how the images are stored, you also might be able to skip the call to mat2gray.&lt;br&gt;
&lt;br&gt;
All the best,&lt;br&gt;
&lt;br&gt;
Pete</description>
    </item>
    <item>
      <pubDate>Tue, 06 Jan 2009 15:00:38 -0500</pubDate>
      <title>Re: Array of Images Running out of memory</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241923#620088</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Arron S&quot; &amp;lt;aps@uwm.edu&amp;gt; wrote in message &lt;br&gt;
news:gjupaq$jeu$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I am very very new to matlab and have written my first M-file. It is &lt;br&gt;
&amp;gt;functional for a test set of 38 images but my data sets are in the range of &lt;br&gt;
&amp;gt;400. (144x512)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; When I try to run it with a full data set I get an obvious memory error. &lt;br&gt;
&amp;gt; I realize that I am running 32bit XP and thus don't have a large enough &lt;br&gt;
&amp;gt; contiguous memory for my data. But I know that others are able to get &lt;br&gt;
&amp;gt; around this and I would like to know how. This should be easy to answer &lt;br&gt;
&amp;gt; since I have read a lot of posts where people have arrays of a good deal &lt;br&gt;
&amp;gt; of images but they did not explain how they were doing it. I looked at a &lt;br&gt;
&amp;gt; few hundred file exchange files and searched this forum before I decided &lt;br&gt;
&amp;gt; to post this message.  I did not find an answer that I understood.  Any &lt;br&gt;
&amp;gt; help or links to topics pointing me in the right direction would be very &lt;br&gt;
&amp;gt; helpful.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; My aim is to load about 400 images and run FRET analysis.&lt;br&gt;
&amp;gt; Below is my code (probably not optimal, and itis currently molded for my &lt;br&gt;
&amp;gt; data with no input/error checks yet) I used ReadDicom4.m by Nipun Patel to &lt;br&gt;
&amp;gt; teach myself some of the basics and hence some of the variables are of the &lt;br&gt;
&amp;gt; same name.&lt;br&gt;
&lt;br&gt;
The first question I'd ask is:  do you need to have all 38 (or 400) images &lt;br&gt;
loaded into memory at the same time?  Can you instead read in one image, &lt;br&gt;
perform the necessary calculations, and then repeat for the remainder of &lt;br&gt;
your images?&lt;br&gt;
&lt;br&gt;
Pete's suggestion about using a different data type may help as well, &lt;br&gt;
particularly if the images can be stored and processed as one of the integer &lt;br&gt;
data types (like int8 or uint8, which would use one eighth the memory of &lt;br&gt;
storing it as a double.)  If all the images can be stored as int8's, for &lt;br&gt;
instance, then preallocate with:&lt;br&gt;
&lt;br&gt;
a = zeros(144, 512, totalFiles, 'int8');&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Tue, 06 Jan 2009 19:57:01 -0500</pubDate>
      <title>Re: Array of Images Running out of memory</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241923#620148</link>
      <author>Arron S</author>
      <description>Thank you all for the help.  I believe the initial problem was that I had fragmented memory from testing because it worked this morning after i restarted the computer with the large data set.  But I also think that processing each image individually will also be a great help for future calculation and I appreciate that tip.  When I get this running I will post again for tips to make it file exchange ready for future users who want to do FRET. &lt;br&gt;
Thanks again,&lt;br&gt;
Arron&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Arron S&quot; &amp;lt;aps@uwm.edu&amp;gt; wrote in message &amp;lt;gjupaq$jeu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I am very very new to matlab and have written my first M-file. It is functional for a test set of 38 images but my data sets are in the range of 400. (144x512)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I try to run it with a full data set I get an obvious memory error.  I realize that I am running 32bit XP and thus don't have a large enough contiguous memory for my data. But I know that others are able to get around this and I would like to know how. This should be easy to answer since I have read a lot of posts where people have arrays of a good deal of images but they did not explain how they were doing it. I looked at a few hundred file exchange files and searched this forum before I decided to post this message.  I did not find an answer that I understood.  Any help or links to topics pointing me in the right direction would be very helpful. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My aim is to load about 400 images and run FRET analysis. &lt;br&gt;
&amp;gt; Below is my code (probably not optimal, and itis currently molded for my data with no input/error checks yet) I used ReadDicom4.m by Nipun Patel to teach myself some of the basics and hence some of the variables are of the same name.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you in advance,&lt;br&gt;
&amp;gt; Arron&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function a = imagestack(sequenceStartNo,sequenceEndNo, fileExtension)&lt;br&gt;
&amp;gt; tic&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fileCount=0;&lt;br&gt;
&amp;gt; totalFiles = sequenceEndNo - sequenceStartNo;&lt;br&gt;
&amp;gt; a= zeros(144,512,totalFiles);  % preallocation&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; j=1;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=sequenceStartNo:sequenceEndNo &lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     sequenceNo=num2str(i);&lt;br&gt;
&amp;gt;     filename = strcat(sequenceNo,fileExtension);&lt;br&gt;
&amp;gt;     varname = imread (filename);&lt;br&gt;
&amp;gt;     varname = mat2gray(varname);&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     fileCount = fileCount + 1;&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     a(:,:,j)= varname;&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     j = j+1;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; toc&lt;br&gt;
&amp;gt; display (fileCount);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; </description>
    </item>
  </channel>
</rss>

