How to load images from variable
5 次查看(过去 30 天)
显示 更早的评论
Hello. I used this code to load images from folder to matlab. It worked well, but i don´t know how to load for example 3. and 5.(it doesn´t matter which one) image from imageArray and show it by figure...so how are images indexed in imageArray? please give me some simple example. i am begginer. thank you
myFolder = 'C:\Users\lukino\Pictures\...';
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);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
0 个评论
回答(1 个)
Image Analyst
2014-2-14
Look like code from the FAQ. What's the problem? What are examples 3 and 5? imageArray is not indexed. It's overwritten each iteration. You read in that image, process it, and then you're done and you move on to the next image.
3 个评论
Image Analyst
2014-2-15
I would not do it that way as it's wasteful of memory. I'd call a function like AnalyzeSingleImage(imageArray) inside the loop. I don't see any need to read all of the images into a cell array and then you'll just have to have another loop after that to process them all after extracting from "x". I have no idea why you're wanting to save all of these images in an "x" array - it doesn't seem necessary to me.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!