How to load images from variable

5 次查看(过去 30 天)
Lukas
Lukas 2014-2-14
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

回答(1 个)

Image Analyst
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 个评论
Lukas
Lukas 2014-2-14
编辑:Image Analyst 2014-2-15
ok a did it..som simple...
imageArray = imread(fullFileName);
** *x{k}=imageArray;* **
imshow(imageArray); % Display image.
still, thank you :)
Image Analyst
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 CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by