MATLAB: ERROR: Index in position 1 exceeds array bounds. Error in mainpgm (line 289) xdata = [DF(1,:);DF(3,:)];, xdata = [DF(2,:);DF(4,:)];

getting error in 2018a version

clc
clear all
close all
cd Database
DF=[];
for i = 1 : 4
%%= READ VIDEO
str = int2str(i);
str = strcat(str,'.bmp');
a1=imread(str)
img =a1;
faceDetector = vision.CascadeObjectDetector();
% Read a video frame and run the detector.

videoFrame = img;
bbox = step(faceDetector, videoFrame);
if isempty(bbox)
break
else
% Draw the returned bounding box around the detected face.

videoOut = insertObjectAnnotation(img,'rectangle',bbox,'Face');
cro=imcrop(img,bbox(1,:));
nor=imresize(cro,[144 120]);
end
% % % DISTORTION FEATURE

cmap = rgb2hsv(nor);
H=cmap(:,:,1);
S=cmap(:,:,2);
V=cmap(:,:,3);
Hmean=mean(mean(H));
Hst=std2(H);
Smean=mean(mean(S));
Sst=std2(S);
Vmean=mean(mean(V));
Vst=std2(V);
Hsk = sum(skewness(H))
Ssk = sum(skewness(S))
Vsk = sum(skewness(V))
Hmin=min(imhist(H))
Hmax=max(imhist(H))
Smin=min(imhist(S))
Smax=max(imhist(S))
Vmin=min(imhist(V))
Vmax=max(imhist(V))
% % % BLurres

LEN = 21;
THETA = 11;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(nor, PSF, 'conv', 'circular');
[m n c]=size(nor)
b1=sum(sum((nor-blurred)))./(m*n)
e1=edge(rgb2gray(nor),'canny')
e2=edge(rgb2gray(blurred),'canny')
b2=sum(sum(e1-e2))./(m*n)
r=nor(:,:,1);
g=nor(:,:,2);
b=nor(:,:,3);
c=cat(3,r,g,b);
hr=imhist(r);
hg=imhist(g);
hb=imhist(b);
H=[hr hg hb ]
out=0
for ii=1:length(H)
if H(ii+1)==H(ii)
out=out+1
else
end
end
for ii=1:length(H)
if H(ii+1)~=H(ii)
out1=out+1
else
end
end
ch=[out(end ) out(end)]
R = specular(10,11,100,[4 5 6],[4 5 6])
FEAT=[Hmean, Hst, Smean, Sst, Vmean, Vst, Hsk, Vsk, Ssk, Hmin, Hmax, Smin, Smax, Vmin, Vmax, b1(1), b2(1), R];
DF=[DF;FEAT];
end
cd ..
inp=input(' ENTER THE TEST IMAGE :')
a1=imread(inp)
img =a1;
faceDetector = vision.CascadeObjectDetector();
% Read a video frame and run the detector.
videoFrame = img;
bbox = step(faceDetector, videoFrame);
if isempty(bbox)
% break
else
% Draw the returned bounding box around the detected face.
videoOut = insertObjectAnnotation(img,'rectangle',bbox,'Face');
cro=imcrop(img,bbox(1,:));
nor=imresize(cro,[144 120])
end
% % % DISTORTION FEATURE
cmap = rgb2hsv(nor);
H=cmap(:,:,1);
S=cmap(:,:,2);
V=cmap(:,:,3);
Hmean=mean(mean(H));
Hst=std2(H);
Smean=mean(mean(S));
Sst=std2(S);
Vmean=mean(mean(V));
Vst=std2(V);
Hsk = sum(skewness(H))
Ssk = sum(skewness(S))
Vsk = sum(skewness(V))
Hmin=min(imhist(H))
Hmax=max(imhist(H))
Smin=min(imhist(S))
Smax=max(imhist(S))
Vmin=min(imhist(V))
Vmax=max(imhist(V))
figure,bar(imhist(V))
title('histogram')
% % % BLurres
LEN = 21;
THETA = 11;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(nor, PSF, 'conv', 'circular');
[m n c]=size(nor)
b1=sum(sum((nor-blurred)))./(m*n)
e1=edge(rgb2gray(nor),'canny')
e2=edge(rgb2gray(blurred),'canny')
b2=sum(sum(e1-e2))./(m*n)
r=nor(:,:,1);
g=nor(:,:,2);
b=nor(:,:,3);
c=cat(3,r,g,b);
hr=imhist(r);
hg=imhist(g);
hb=imhist(b);
H=[hr hg hb ]
out=0
for ii=1:length(H)
if H(ii+1)==H(ii)
out=out+1
else
end
end
for ii=1:length(H)
if H(ii+1)~=H(ii)
out1=out+1
else
end
end
ch=[out(end ) out(end)]
R = specular(10,11,100,[4 5 6],[4 5 6])
QF=[Hmean Hst Smean Sst Vmean Vst Hsk Vsk Ssk Hmin Hmax Smin Smax Vmin Vmax b1(1) b2(1) R ];
figure,
subplot(2,2,1)
imshow(a1 );
title('input');
subplot(2,2,2)
imshow(videoOut );
title('face detected');
subplot(2,2,3)
imshow(cro);
title('face image ');
subplot(2,2,4)
imshow(nor);
title('normalised');
xdata = [DF(1,:);DF(3,:)];
group = [1 -1];
svmStruct = svmtrain(xdata,group);
out = svmclassify(svmStruct,QF)
xdata = [DF(2,:);DF(4,:)];
group = [1 -1];
svmStruct = svmtrain(xdata,group);
out1 = svmclassify(svmStruct,QF)
outfuse=out*out1
if outfuse==1
msgbox('ORIGINAL-IMAGE')
else
msgbox('SPOOF-IMAGE')
end

Best Answer

One of the images has no detected face. you break the for loop before appending the DF for that image the remaining images .
Related Question