How to load images from variable

5 views (last 30 days)
Lukas
Lukas on 14 Feb 2014
Commented: Image Analyst on 15 Feb 2014
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

Answers (1)

Image Analyst
Image Analyst on 14 Feb 2014
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 Comments
Lukas
Lukas on 14 Feb 2014
Edited: Image Analyst on 15 Feb 2014
ok a did it..som simple...
imageArray = imread(fullFileName);
** *x{k}=imageArray;* **
imshow(imageArray); % Display image.
still, thank you :)
Image Analyst
Image Analyst on 15 Feb 2014
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.

Sign in to comment.

Categories

Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!