Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
error message?

Subject: error message?

From: Z A

Date: 29 May, 2012 14:59:05

Message: 1 of 4

Hello

I am trying to track 36438 images. Each image is 128X512 an is unit8. A binary image, background black and high intensity structures white.
I created the following code to read the images, following that I track the structures:

for i=1:36438
    n=int2str(i);
    a=strcat('frame',n,'.tif');
    disp(a);
    x=imread(a);
    data(:,:,i)=x;
end

save('video','data');

It iterates from image1 to image6144 and then I get an error message saying:
??? Maximum variable size allowed by the program is exceeded. So I am guessing it's a memory issue.

How do i rectify this problem with the above code, can anyone help please!

Thank you,
Z

Subject: error message?

From: Steven_Lord

Date: 29 May, 2012 15:26:09

Message: 2 of 4



"Z A" <nospam-rekabi570@yahoo.ca> wrote in message
news:jq2o7p$p9o$1@newscl01ah.mathworks.com...
> Hello
> I am trying to track 36438 images. Each image is 128X512 an is unit8. A
> binary image, background black and high intensity structures white.
> I created the following code to read the images, following that I track
> the structures:
>
> for i=1:36438
> n=int2str(i);
> a=strcat('frame',n,'.tif');
> disp(a);
> x=imread(a);
> data(:,:,i)=x;
> end
>
> save('video','data');
>
> It iterates from image1 to image6144 and then I get an error message
> saying:
> ??? Maximum variable size allowed by the program is exceeded. So I am
> guessing it's a memory issue.

Each image has this many elements:

>> oneImage = 128*512
oneImage =
       65536

All of them together would have:

>> allImages = 36438*oneImage
allImages =
                2388000768

If stored as uint8, they would require this much memory _in a contiguous
block_:

>> allMemoryBytes = 1*allImages
allMemoryBytes =
                2388000768
>> allMemoryGB = allMemoryBytes/(1024^3)
allMemoryGB =
           2.2239990234375

But I'm guessing that your x and data are actually being stored as double
precision values, in which case they'd require:

>> allMemoryBytes = 8*allImages
allMemoryBytes =
               19104006144
>> allMemoryGB = allMemoryBytes/(1024^3)
allMemoryGB =
             17.7919921875

If you're on a 32-bit system, you cannot have a contiguous block of memory
that large.

http://www.mathworks.com/help/matlab/matlab_prog/resolving-out-of-memory-errors.html

Even on a 64-bit system, it's unlikely you'll have a contiguous block of
memory that large due to fragmentation, unless your machine has a LOT of
memory and you're not doing anything on it but using MATLAB.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: error message?

From: Z A

Date: 29 May, 2012 16:42:05

Message: 3 of 4

Thanks Steven! Do you recommend a nested loop?
Best



"Steven_Lord" <slord@mathworks.com> wrote in message <jq2pqg$3lg$1@newscl01ah.mathworks.com>...
>
>
> "Z A" <nospam-rekabi570@yahoo.ca> wrote in message
> news:jq2o7p$p9o$1@newscl01ah.mathworks.com...
> > Hello
> > I am trying to track 36438 images. Each image is 128X512 an is unit8. A
> > binary image, background black and high intensity structures white.
> > I created the following code to read the images, following that I track
> > the structures:
> >
> > for i=1:36438
> > n=int2str(i);
> > a=strcat('frame',n,'.tif');
> > disp(a);
> > x=imread(a);
> > data(:,:,i)=x;
> > end
> >
> > save('video','data');
> >
> > It iterates from image1 to image6144 and then I get an error message
> > saying:
> > ??? Maximum variable size allowed by the program is exceeded. So I am
> > guessing it's a memory issue.
>
> Each image has this many elements:
>
> >> oneImage = 128*512
> oneImage =
> 65536
>
> All of them together would have:
>
> >> allImages = 36438*oneImage
> allImages =
> 2388000768
>
> If stored as uint8, they would require this much memory _in a contiguous
> block_:
>
> >> allMemoryBytes = 1*allImages
> allMemoryBytes =
> 2388000768
> >> allMemoryGB = allMemoryBytes/(1024^3)
> allMemoryGB =
> 2.2239990234375
>
> But I'm guessing that your x and data are actually being stored as double
> precision values, in which case they'd require:
>
> >> allMemoryBytes = 8*allImages
> allMemoryBytes =
> 19104006144
> >> allMemoryGB = allMemoryBytes/(1024^3)
> allMemoryGB =
> 17.7919921875
>
> If you're on a 32-bit system, you cannot have a contiguous block of memory
> that large.
>
> http://www.mathworks.com/help/matlab/matlab_prog/resolving-out-of-memory-errors.html
>
> Even on a 64-bit system, it's unlikely you'll have a contiguous block of
> memory that large due to fragmentation, unless your machine has a LOT of
> memory and you're not doing anything on it but using MATLAB.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: error message?

From: Steven_Lord

Date: 30 May, 2012 14:22:58

Message: 4 of 4



"Z A" <nospam-rekabi570@yahoo.ca> wrote in message
news:jq2u8t$n3c$1@newscl01ah.mathworks.com...
> Thanks Steven! Do you recommend a nested loop?

I recommend not trying to create such a large array! Why do you need to
store all 36,438 images in one array anyway? Process each image in turn, so
you only need to have one (or a handful, if your processing requires an
image and its "neighbors") in memory at a time.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us