How do I read images from a folder and save it in a folder ( all in a loop)
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Mansell Teh
 le 1 Oct 2016
  
    
    
    
    
    Commenté : Walter Roberson
      
      
 le 1 Oct 2016
            clear all
clc
%Detect objects using Viola-Jones Algorithm
imgdir = 'C:\Users\Lewis\Documents\MATLAB\testingimage';
DestDir = 'C:\Users\Lewis\Documents\MATLAB\violajones\croppedimage';
%To detect Face
FDetect = vision.CascadeObjectDetector;
images = imgdir('*.jpg');
numfiles = length(images);
myimage = cell(1,numfiles);
for k = 1:numfiles
myimage{k} = imread(images(k).name);
%Returns Bounding Box values based on number of objects
BB = step(FDetect,myimage{k});
for i = 1:size(BB,1)
      rectangle('Position',BB(i,:),'LineWidth',5,'LineStyle','-','EdgeColor','r');
      cropimage = imcrop(myimage{k},BB(i,:));
  end   
      filename = ['testingimage' ,num2str(k),'.jpg'];
      save(filename);
end
This is what I did, but I think there is some problem with it.
0 commentaires
Réponse acceptée
  Walter Roberson
      
      
 le 1 Oct 2016
        images = dir( fullfile(imgdir, '*.jpg') );
and
myimage{k} = imread( fullfile( imgdir, images(k).name) );
and instead of
save(filename);
use
imwrite(croppedimage, fullfile(DestDir, filename));
2 commentaires
  Walter Roberson
      
      
 le 1 Oct 2016
				To use as output the original name but with a suffix, then:
   name_suffix = '(01)';
[in_dir, in_basename, in_ext] = fileparts( images(k).name );
filename = [in_basename name_suffix in_ext];
instead of
filename = ['testingimage' ,num2str(k),'.jpg'];
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Tracking and Motion Estimation dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

