i want to save names of the images(frame_0000, frame_0001, frame_0003........) in a text file by reading them from a folder.
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    sidra Rafique
 am 14 Aug. 2018
  
    
    
    
    
    Kommentiert: sidra Rafique
 am 15 Aug. 2018
            i want to save names of the images(frame_0000, frame_0001, frame_0003........) in a text file by reading them from a folder. somehow i am getting errors while writing the code. As i am new to MatLab please help me. Waiting for your response.
1 Kommentar
  Geoff Hayes
      
      
 am 14 Aug. 2018
				sidra - somehow i am getting errors while writing the code. What is the code? What are the errors?
Akzeptierte Antwort
  Stephen23
      
      
 am 14 Aug. 2018
        
      Bearbeitet: Stephen23
      
      
 am 14 Aug. 2018
  
      D = 'directory where images are';
S = dir(fullfile(D,'*.jpg'));
% Save filenames:
[fid,msg] = fopen('names.txt','wt');
assert(fid>=3,msg)
fprintf(fid,'ImageName\n')
fprintf(fid,'%s\n',S.name)
fclose(fid);
% Load files:
for k = 1:numel(S)
    Im = imread(fullfile(D,S(k).name));
    ...
end
This uses S.name to generate a comma-separated list, and so each filename gets printed to the textfile.
9 Kommentare
  Stephen23
      
      
 am 15 Aug. 2018
				
      Bearbeitet: Stephen23
      
      
 am 15 Aug. 2018
  
			@sidra Rafique: your code duplicates printing the filenames, and you need to add a separator/delimiter character between the filename and the value. Try something like this:
c = {S.name};
c(2,:) = num2cell(d);
[fid,msg] = fopen('names.txt','wt');
assert(fid>=3,msg);
fprintf(fid, '%s,%s\n','Imagename','Diameter');
fprintf(fid, '%s,%3.4f\n',c{:});
fclose(fid);
Note how I used the comma as a delimiter, and the filenames are included in c, so you do not need to print them again.
Weitere Antworten (1)
  Yuvaraj Venkataswamy
      
 am 14 Aug. 2018
        Check below link. https://in.mathworks.com/matlabcentral/answers/333532-how-to-extract-and-save-frames-in-a-video
In your case you can use below command.
 if true
     imwrite(frames, fullfile(f_folder,sprintf ('%frame_04d.jpg', nFrame)));
  end
1 Kommentar
Siehe auch
Kategorien
				Mehr zu Read, Write, and Modify Image 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!