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 Kommentare

KSSV
KSSV am 14 Dez. 2016
What is size of BB? Put your code in debugging mode and check line by line.
Isha Pandya
Isha Pandya am 14 Dez. 2016
In the line, for i=1:size(BB,1) what does 1 in the bracket indicate ? Can you please explain me as I am new to matlab.
Isha Pandya
Isha Pandya am 14 Dez. 2016
while debugging it says value of BB is [168,253,79,48] and min=48, max=253.
Ganesh Hegade
Ganesh Hegade am 14 Dez. 2016
Bearbeitet: Ganesh Hegade am 14 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 15 Dez. 2016

0 Stimmen

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

Gefragt:

am 14 Dez. 2016

Beantwortet:

am 15 Dez. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by