I have following code, i want to perform following task on many images reading from directory. kindly help me through code.

1 view (last 30 days)
saeeda saher
saeeda saher on 29 Nov 2017
Commented: saeeda saher on 2 Dec 2017
I=imread('E:\a.jpg');
figure(1),imshow(I);
FaceDetect = vision.CascadeObjectDetector;
BB = step(FaceDetect,I);
figure(2),imshow(I);
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',3,'LineStyle','- ','EdgeColor','r');
end
for i = 1:size(BB,1)
J= imcrop(I,BB(i,:));
% figure(3),subplot(5,5,i);imshow(J);
fname = sprintf('b_cropped_%d.jpg', i);
fpath = fullfile('E:\face', fname);
imwrite(J, fpath)
% imwrite(J,'E:\g_cropped.jpg')
end
  2 Comments

Sign in to comment.

Answers (1)

Jan
Jan on 29 Nov 2017
Edited: Jan on 29 Nov 2017
Simply replace
I = imread('E:\a.jpg');
by
Folder = 'E:\';
FileList = dir(fullfile(Folder, '*.jpg'));
for iFile = 1:numel(FileList)
File = fullfile(Folder, FileList(iFile).name);
I = imread(File);
...
% Consider the name or index of the original file:
fname = sprintf('b_cropped_%d_%d.jpg', iFile, i);
...
end

Community Treasure Hunt

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

Start Hunting!