Info

This question is closed. Reopen it to edit or answer.

How can I insert my images in one array of size [224,224,3180]?

1 view (last 30 days)
I have a dataset contains 106 persons each one has a 30 images of size (224 x 224) pixels. I want to put them all together in one matrix of size [224,224,3180]. I've built this code it works fine and does what I need, put the problem is when I do load for my matrix it takes long time to load up into Matlab Workspace. Is there any way to make it faster and efficient.
Your help in this regard is highly appreciated.
RightIris_Training224=zeros(224,224,3180);
k=1;
for i=1:106
for j=1:30
% The names of my images like this (1-1,1-2,....1-30)
str1 = num2str(i);
str2=num2str(j);
str3= strcat(str1,'-',str2,'.bmp');
str4 = strcat('F:\SDUMLA-HMT\',str3);
img = imread(str4);
RightIris_Training224(:,:,k)= mat2gray(img);
k=k+1;
end
end
save RightIris_Training224 RightIris_Training224

Answers (1)

Walter Roberson
Walter Roberson on 18 Feb 2016
You could fwrite() RightIrix_Training224, and fread() it when you needed it.
Note that if your bmp files are uint8 images (not uncommon) then you are making the storage requirements 8 times higher by using mat2gray(), which is part of what contributes to the reading being slow. I would not be surprised if it was faster to save() as a uint8 3D array and load() that, and convert to the 0/1 range if you needed to.
A question along those lines is whether you are counting upon the fact that when you use mat2gray(A) with no range provided, then it scales so that max(A(:)) becomes 1 and min(A(:)) becomes 0? If so then redoing that calculation each time you load() might not be efficient enough. But if you know that your png range from 0 to 255 anyhow (or should) then the scaling calculation becomes trivial after loading the uint8 3D array.

Community Treasure Hunt

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

Start Hunting!