How to save images in a folder?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Ganesh Hegade
2016년 12월 14일
편집: Ganesh Hegade
2016년 12월 14일
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.
답변 (1개)
KSSV
2016년 12월 15일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!