Read images from folder
    2 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    sami ullah
 am 30 Dez. 2020
  
    
    
    
    
    Beantwortet: Image Analyst
      
      
 am 30 Dez. 2020
            I have the following code for reading 200 images from a folder.
for i=1:200
img(i)=imread('..\TRAINING SET\a(i).BMP','bmp'); 
end
save('TRAINING SET.mat','img');
following error is displayed:
Error using imread (line 387)
File "..\TRAINING SET\a(i).BMP" does not exist.
Error in trainingset (line 2)
img(i)=imread('..\TRAINING SET\a(i).BMP','bmp');
1 Kommentar
  Walter Roberson
      
      
 am 30 Dez. 2020
				
      Bearbeitet: Image Analyst
      
      
 am 30 Dez. 2020
  
			Consider using imageDatastore().
Akzeptierte Antwort
  Image Analyst
      
      
 am 30 Dez. 2020
        See the code snippet in the FAQ:
Which you'd adjust like this:
% Specify the folder where the files live.
myFolder = fullfile(pwd, '..\TRAINING SET');
% Check to make sure that folder actually exists.  Warn user if it doesn't.
if ~isfolder(myFolder)
    errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
    uiwait(warndlg(errorMessage));
    myFolder = uigetdir(); % Ask for a new one.
    if myFolder == 0
         % User clicked Cancel
         return;
    end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.BMP'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
    baseFileName = theFiles(k).name;
    fullFileName = fullfile(theFiles(k).folder, baseFileName);
    fprintf(1, 'Now reading %s\n', fullFileName);
    % Now do whatever you want with this file name,
    % such as reading it in as an image array with imread()
    imageArray = imread(fullFileName);
    imshow(imageArray);  % Display image.
    drawnow; % Force display to update immediately.
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


