Memory issue to create 4D array

1 view (last 30 days)
Shehzad Ali
Shehzad Ali on 7 Apr 2019
Commented: Walter Roberson on 8 Apr 2019
I have 35000 funds image data-set i want to create 4D array of this data-set but when i ran the code and read images one by one than error occurred memory limitation . plz help me to resolve issue.
my code is here.
close all
clear all
Directory= 'C:\Users\Shehzad\Desktop\sample\*.jpeg';
Imgs = dir(Directory);
for j=1:length(Imgs)
thisname = Imgs(j).name;
D=Imgs(j).folder;
thisfile = fullfile(D, thisname);
Img = imread(thisfile); % try to read image
data(:,:,:,j)=Img;
clear Img;
end
save Data data
save Imgs Imgs
Output is:
Requested 2500x2700x3x630 (11.9GB) array exceeds maximum array size preference. Creation of arrays greater than this limit
may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more
information.
Error in Project (line 10)
data(:,:,:,j)=Img;

Answers (1)

Rik
Rik on 7 Apr 2019
The amount of data is probably huge, is not pre-allocated and will probably not fit in memory. Have you calculated an estimated size of the needed array?
If you can't add fysical RAM to your system, there are some tools that you can use to access data still on your disk and only load them to RAM when you need it, like datastore and imageDatastore.
  6 Comments
Shehzad Ali
Shehzad Ali on 8 Apr 2019
I am working on Dibatic retinopathy dectection using convolutional neural network. once i made it then I load one by one image through imageDatastore.
Walter Roberson
Walter Roberson on 8 Apr 2019
Here it sounds like the "one by one image" that you intend to load with imageDatastore would be each of the three 4D arrays that are 115 gigabytes each ??
I thought Diabetic Retinopathy involved individual RGB images (so 3D), rather than volume scans or time series ?

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!