how to read all the images in a folder?

Illustration
Aps - 2023-08-08T14:45:57+00:00
Question: how to read all the images in a folder?

how to read the all the images present in a folder  

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

You can use dir to get a structure with of the files listed, and you can use a wildcard search too:

 

myFolder = 'C:\Documents and Settings\yourUserName\My Documents\My 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

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!