Home > Archive > Matlab > September 2006 > Maximum variable size allowed by the program is exceeded.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Maximum variable size allowed by the program is exceeded.
|
|
|
| Matlab version: 2006a
variable types: uint8
Error: Maximum variable size allowed by the program is exceeded.
Description: I am using the imresize function on a 32 image array of
480-640 images. Im running it in sequnce, one image at at time and
then writing each image to the hard disk and clearnig the variable to
free memory. The resultant image is 4320x5760 and stores at roughly
25mb. The program makes it 16 iterations and then I get specified
error saying there is no more variables allowed.
Problem Code
1. for n = 1:maxnum;
2. array(:,:,n) = imresize(A(:,:,n), superresolution,'nearest');
3. filename = [tempdir, num2str(n), '.bmp'];
4. imwrite(array(:,:,n),filename,'bmp');
5. clear array
6. end
Variables
K>> whos
Name Size Bytes Class
A 480x640x32 9830400 uint8
array
Directional 1x1 8 double
array
Dirname 1x56 112 char
array
MPGain 1x1 8 double
array
MaxGain 1x1 8 double
array
MeanGain 1x1 8 double
array
MedianGain 1x1 8 double
array
Searchname 1x5 10 char
array
TraditionalRMS 1x1 8 double
array
array 4320x5760 24883200 uint8
array
concated 1x62 124 char
array
files 32x1 9870 struct
array
fullsearch 1x61 122 char
array
maxnum 1x1 8 double
array
maxnumrotate 1x1 8 double
array
mnumber 1x1 8 double
array
n 1x1 8 double
array
superresolution 1x1 8 double
array
tempdir 1x3 6 char
array
test 1x6 12 char
array
x_center 1x1 8 double
array
x_y_pix_length 1x1 8 double
array
y_center 1x1 8 double
array
===
Ill even give out the full code up to that point in the program
clear;
superresolution = 9
mnumber = 88888 %88888
maxnum = 32 %amount of images used in derotation
maxnumrotate = 32
Dirname = 'Z:\public_html\research\dataASCRMS\rawd
ata\4-10-breast9' %
CP388-223
x_center = 385 %Vertical Center Point
y_center = 222 %horizontal Centerpoint
x_y_pix_length = 330 %this is the boundary of the total image
target
Directional = -1 % use negative if image is rotated counter
clockwise
path(path,'scripts') %path to my scripts
tempdir = 'e:'
%%Set Gain to 0 to skip routine - SAVES TIME
MeanGain = 0 %10
MedianGain = 0 %SLOW 1 %3.4
MaxGain = 0 %SLOW 1 % 1.5
MPGain = 0.34 %0.535
TraditionalRMS = 0 %SLOW 0.1
%IMPORT DATA FROM WORKING DIRECTORY
Dirname = [Dirname, '']
Searchname = '*.bmp';
fullsearch = [Dirname, Searchname];
files = dir(fullsearch);
for n = 1:maxnum;
test = [num2str(n), '.bmp'];
concated = [Dirname, test];
A(:,:,n)= imread(concated);
end
%SUPER RESOLUTION
for n = 1:maxnum;
array(:,:,n) = imresize(A(:,:,n), superresolution,'nearest');
filename = [tempdir, num2str(n), '.bmp']; %concat filename
so goes into dat directory under running file
imwrite(array(:,:,n),filename,'bmp'); % write the file out
cle
| |
| Roger Stafford 2006-09-28, 7:05 pm |
| In article <ef42662.-1@webcrossing.raydaftYaTP>, jimmy
<jimmy@engr.uconn.edu> wrote:
> ------- imresize woes --------
------------------------
If I were in your shoes, I would alter the class of the 'A' variable
from 'uint8' to something of larger capacity such as 'double', and do a
study of the maximum sizes of the values in 'array' coming out of
'imresize'. If your error message is to be taken literally, 'array' may
be receiving values beyond 255 or below 0 from 'imresize', which would be
beyond the capacity of 'uint8' variables. With your expansion by 3 each
way, I can conceive of extrapolation taking place at the borders involving
pixels with values of 255 or 0 and leading to such an unhappy result, but
in my mind that would constitute a bug on MathWorks' part if they claim to
support the 'uint8' class for 'imresize'.
Roger Stafford
| |
| Titus Edelhofer 2006-09-29, 4:13 am |
| Hi Roger,
the error message about the variable size says, that the variable
has too many entries, not that it leaves the 0-255 range...
To the original question:
- why do you store each image, because it seems to me, you
are more interested in saving it again to another file?
- for 32 images of size 4320*5760 you would have
4320*5760*32 = 760MB memory, which is just around
the boundary of the largest matrix allowed (hence the error
message)
So I'd suggest:
1. for n = 1:maxnum;
2. array = imresize(A(:,:,n), superresolution,'nearest');
3. filename = [tempdir, num2str(n), '.bmp'];
4. imwrite(array,filename,'bmp');
5. % no need to clear array
6. end
Titus
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> schrieb im
Newsbeitrag
news:ellieandrogerxyzzy-2809061747430001@dialup-4.232.57.27.dial1.losangeles1.level3.net...
> In article <ef42662.-1@webcrossing.raydaftYaTP>, jimmy
> <jimmy@engr.uconn.edu> wrote:
>
>
> ------------------------
> If I were in your shoes, I would alter the class of the 'A' variable
> from 'uint8' to something of larger capacity such as 'double', and do a
> study of the maximum sizes of the values in 'array' coming out of
> 'imresize'. If your error message is to be taken literally, 'array' may
> be receiving values beyond 255 or below 0 from 'imresize', which would be
> beyond the capacity of 'uint8' variables. With your expansion by 3 each
> way, I can conceive of extrapolation taking place at the borders involving
> pixels with values of 255 or 0 and leading to such an unhappy result, but
> in my mind that would constitute a bug on MathWorks' part if they claim to
> support the 'uint8' class for 'imresize'.
>
> Roger Stafford
| |
| Jeroen 2006-09-29, 4:13 am |
| jimmy wrote:
> Matlab version: 2006a
> variable types: uint8
> Error: Maximum variable size allowed by the program is exceeded.
>
> Description: I am using the imresize function on a 32 image array of
> 480-640 images. Im running it in sequnce, one image at at time and
> then writing each image to the hard disk and clearnig the variable to
> free memory. The resultant image is 4320x5760 and stores at roughly
> 25mb. The program makes it 16 iterations and then I get specified
> error saying there is no more variables allowed.
>
> Problem Code
> 1. for n = 1:maxnum;
> 2. array(:,:,n) = imresize(A(:,:,n), superresolution,'nearest');
> 3. filename = [tempdir, num2str(n), '.bmp'];
> 4. imwrite(array(:,:,n),filename,'bmp');
> 5. clear array
> 6. end
I don't see any benefits of using 'array(:,:,n)' in your code. For a
certain value of 'n' in your loop, the statement:
array(:,:,n) = imresize(A(:,:,n), superresolution,'nearest');
results in a 3-dimensional array with size 4320 x 5760 x n. So for n=16
you are allocating 16x25 Mb = 400 Mb at once, which may be the
problem... Rewrite as:
for n = 1:maxnum;
superres_image = imresize(A(:,:,n), superresolution,'nearest');
filename = [tempdir, num2str(n), '.bmp'];
imwrite(superres_image,filename,'bmp');
end
Not tested, just a guess....
Jeroen
| |
| Rune Allnor 2006-09-29, 4:13 am |
|
Jeroen skrev:
> jimmy wrote:
>
> I don't see any benefits of using 'array(:,:,n)' in your code. For a
> certain value of 'n' in your loop, the statement:
>
> array(:,:,n) = imresize(A(:,:,n), superresolution,'nearest');
>
> results in a 3-dimensional array with size 4320 x 5760 x n. So for n=16
> you are allocating 16x25 Mb = 400 Mb at once, which may be the
> problem...
I agree with Jeroen in the diagnosis. Since you write the
image to file anyway, use a 2D array instead of 3D.
Corrections below:
1. for n = 1:maxnum;
%2. array(:,:,n) = imresize(A(:,:,n), superresolution,'nearest');
2. array = imresize(A(:,:,n), superresolution,'nearest');
3. filename = [tempdir, num2str(n), '.bmp'];
% 4. imwrite(array(:,:,n),filename,'bmp');
4. imwrite(array,filename,'bmp');
%5. clear array;
6. end
Rune
| |
|
| the comments on array(:,:,:) were helpful as turning it into a 2d
array is allowing it to work.
somehow the "clear array" command was not clearing variable, it
should have freed all the memory in array(:,:,:) and accoriding to
memory management it was.
yea, the program works with imresize of 5x the orignal image, but
after that (6x and on), im now resoring to have to save the images to
disk due to running out of memory. With imresize of 7 and on, I get
errors with running out of variables. Its kind of a PITA to have to
rewrite working code to accomodate this..
thanks for the time..
| |
|
|
|
|
|