I have 16 GB of RAM, why can't I load a 3.5 GB file?

5 views (last 30 days)
Hi,
I'm trying to load a video file containing thermal imaging data with a resolution of 512x640 pixels and 6000 frames.
For that reason, I want to preallocate a matrix of data type uint16, 512x640x6000 entries big.
However, Matlab tells me it runs out of memory with those settings.
Typing memory in the command line tells me the following:
Maximum possible array: 10367 MB (1.087e+10 bytes) *
Memory available for all arrays: 10367 MB (1.087e+10 bytes) *
Memory used by MATLAB: 1758 MB (1.843e+09 bytes)
Physical Memory (RAM): 16319 MB (1.711e+10 bytes)
* Limited by System Memory (physical + swap file) available.
So I don't get why I can't create that matrix. I should have more than enough memory just in RAM, not even counting swapping space on the hard drive.
Can anyone tell me how I can get that file loaded?
Thanks in advance.
  2 Comments
Stephen23
Stephen23 on 19 Mar 2020
" I want ot preallocate a matrix of data type uint16, 512x640x6000 entries big"
Exactly how did you try to do that? Please show the exact code you tried.
Korbi
Korbi on 19 Mar 2020
It's part of a program I got from my academic supervisor, but since my University is currently shut down due to the virus, I can't contact him about it. Also the code was written by a former student of his, I'm not sure if he'd know the ins and outs.
The lines that produce the error are:
frames=6001;%only for demonstration purposes, number of frames is read from the unpacked video file
zeilen=512; %Resolution
spalten=640;
video=uint16(zeros(zeilen,spalten,frames));

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 19 Mar 2020
Edited: Stephen23 on 19 Mar 2020
This line has very inefficient use of memory, and is likely the cause of the error:
video=uint16(zeros(zeilen,spalten,frames));
The zeros call creates a double array (not an integer array) with the requested size, which will not fit in your memory. Its author intended that after it is created it should be converted to integer by uint16: it is a very inefficient use of memory to create a large double array which would only exist for a moment before being converted to integer and then simply discarded. In case you were curious, its size in memory would be:
>> 512*640*6000 * 64/8 % bytes
ans = 1.5729e+10
which is clearly larger than your maximum permitted array size. The solution is very simple:
video = zeros(zeilen,spalten,frames,'uint16');
which will have size in memory:
>> 512*640*6000 * 16/8 % bytes
ans = 3.9322e+09

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!