How to save images in a folder?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to read 2 images, do something to those images and then save those two images in a folder. I have used for loop. I am able to read both the images but only first image is getting saved in the folder. Following is my code. What changes should be done in order to save both the images in a folder.
c=cell(1,2);
for m=1:2
I=imread(sprintf('isha%d.jpg',m));
%To detect Mouth
MouthDetect = vision.CascadeObjectDetector('Mouth','MergeThreshold',120);
BB=step(MouthDetect,I);
figure,
imshow(I); hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','r');
end
x=imcrop(I,BB);
y= imcomplement(x);
figure, imshow(y);
imwrite(y,strcat('D:\implementation\featurescrop\mouth__',num2str(i),'.jpg'));
hold off;
%To detect Eyes
EyeDetect = vision.CascadeObjectDetector('EyePairBig');
BB=step(EyeDetect,I);
hold on
rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','b')
x=imcrop(I,BB);
y= imcomplement(x);
figure, imshow(y);
imwrite(y,strcat('D:\implementation\featurescrop\eyes__',num2str(i),'.jpg'));
hold off;
%to detect nose
NoseDetect = vision.CascadeObjectDetector('Nose','MergeThreshold',85);
BB=step(NoseDetect,I);
figure,
imshow(I); hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','b');
end
title('Nose Detection');
hold off;
x=imcrop(I,BB);
y= imcomplement(x);
figure, imshow(y);
imwrite(y,strcat('D:\implementation\featurescrop\nose__',num2str(i),'.jpg'));
hold off;
end
4 Commenti
Ganesh Hegade
il 14 Dic 2016
Modificato: Ganesh Hegade
il 14 Dic 2016
size command always return 1x2 double data. for example if
BB = [168,253,79,48];
>> size(BB)
ans =
1 4
size(BB,1) gives only the first value of the output.
BB = [168,253,79,48];
>> size(BB,1)
ans =
1
So in your code loop is running for only first element.
Risposte (1)
KSSV
il 15 Dic 2016
As the size(BB,1) is 1, your loop runs only for once....As you said you are reading two images....change loop to:
for i = 1:2
%%%%
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!