Saving Image Dataset in Array
显示 更早的评论
I have number of 17327 jpg files in my dataset. I need to save them in an array with dimensions [number of images, 224,224,3] . All images are 224x224. When try code below, it gives array that 'imageArray' with 224x1087968x3
myFolder = 'C:\Users\karab\Desktop\BİTİRME\validation';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
imageArray=[]
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = [imageArray imread(fullFileName)];
%imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
1 个评论
Adam
2019-3-6
Pre-allocate imageArray to be the correct size and assign the new image by indexing rather than concatenation. You know what size it needs to be upfront so just create it, e.g.
imageArray = zeros( numel( jpegFiles ), 224, 224, 3 );
Although if you can get the 224 from somewhere rather than hard-code it then that would be better too.
Then:
imageArray( k, :, :, : ) = imread( fullFileName );
in your loop should work, assuming your images are true RGB and not inidexed greyscale images.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!