Saving Image Dataset in Array
2 ビュー (過去 30 日間)
古いコメントを表示
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!