Saving Image Dataset in Array

조회 수: 8 (최근 30일)
Trevor Badji
Trevor Badji 2019년 3월 6일
댓글: Adam 2019년 3월 6일
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
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개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by