How to solve Index exceeds matrix dimensions problem?

The error 'Index exceeds matrix dimensions' in A New Fast And Efficient Hmm based Face Recognition system using a 7 state hmm along with SVD Coefficients i done my coding in 2017a Matlab version please rectify my error. Many days i searching the solution i didn't get that.

5 commentaires

You have not shown us your code or shown us the line that has the error.
sruthi N
sruthi N le 14 Déc 2017
Modifié(e) : Walter Roberson le 14 Déc 2017
sorry Sir
if (exist('DATABASE.mat','file'))
load DATABASE.mat;
end
while (1==1)
choice=menu('Face Recognition',...
'Generate Database',...
'Calculate Recognition Rate',...
'Recognize from Image',...
'Contents of Folder',...
'Result Comparison',...
'Exit');
if (choice ==1)
if (~exist('DATABASE.mat','file'))
[myDatabase,minmax] = gendata();
else
pause(0.1);
choice2 = questdlg('Generating a new database will remove any previous trained database. Are you sure?', ...
'Warning...',...
'Yes', ...
'No','No');
switch choice2
case 'Yes'
pause(0.1);
[myDatabase,minmax] = gendata();
case 'No'
end
end
end
if (choice == 2)
if (~exist('myDatabase','var'))
fprintf('Please generate database first!\n');
else
recognition_rate = testsys(myDatabase,minmax);
end
end
if (choice == 3)
if (~exist('myDatabase','var'))
fprintf('Please generate database first!\n');
else
pause(0.1);
[file_name file_path] = uigetfile ({'*.pgm';'*.jpg';'*.png'});
if file_path ~= 0
filename = [file_path,file_name];
facerec (filename,myDatabase,minmax);
end
end
end
if(choice == 4)
prompt='Please enter Folder No(From 1 to 40):';
z=input(prompt);
a=('./data/s')
z=num2str(z);
z1=strcat(a,z);
dir(z1)
for (i=1:1:10)
i=num2str(i);
a11='/';
a11=strcat(a11,i);
a1='.pgm';
a2=strcat(a11,a1);
a3=strcat(z1,a2);
figure
subplot(1,2,1), imshow(a3)
pause(1)
end
end
if (choice == 5)
d1= [96.5,87.5];
bar(d1,0.2)
legend('1-Proposed','2-Existing')
end
if (choice == 6)
clear choice choice2
return;
end
end
ERROR
Loading Faces ...
Index exceeds matrix dimensions.
Error in gendata (line 51)
blk_coeffs = myDatabase{1,person_index}{block_index,image_index};
Error in mainmenu (line 30)
[myDatabase,minmax] = gendata();
You did not show the source for gendata
sruthi N
sruthi N le 14 Déc 2017
Modifié(e) : Walter Roberson le 14 Déc 2017
Function of the Gendata
function [myDatabase,minmax] = gendata()
eps=.000001;
ufft = [1 5 6 8 10];
fprintf ('Loading Faces ...\n');
data_folder_contents = dir ('./data');
myDatabase = cell(0,0);
person_index = 0;
max_coeffs = [-Inf -Inf -Inf];
min_coeffs = [ Inf 0 0];
for person=1:size(data_folder_contents,1);
if (strcmp(data_folder_contents(person,1).name,'.') || ...
strcmp(data_folder_contents(person,1).name,'..') || ...
(data_folder_contents(person,1).isdir == 0))
continue;
end
person_index = person_index+1;
person_name = data_folder_contents(person,1).name;
myDatabase{1,person_index} = person_name;
fprintf([person_name,' ']);
person_folder_contents = dir(['./data/',person_name,'/*.pgm']);
blk_cell = cell(0,0);
for face_index=1:5
I = imread(['./data/',person_name,'/',person_folder_contents(ufft(face_index),1).name]);
I = imresize(I,[56 46]);
I = ordfilt2(I,1,true(3));
blk_index = 0;
for blk_begin=1:52
blk_index=blk_index+1;
blk = I(blk_begin:blk_begin+4,:);
[U,S,V] = svd(double(blk));
blk_coeffs = [U(1,1) S(1,1) S(2,2)];
max_coeffs = max([max_coeffs;blk_coeffs]);
min_coeffs = min([min_coeffs;blk_coeffs]);
blk_cell{blk_index,face_index} = blk_coeffs;
end
end
myDatabase{2,person_index} = blk_cell;
if (mod(person_index,10)==0)
fprintf('\n');
end
end
delta = (max_coeffs-min_coeffs)./([18 10 7]-eps);
minmax = [min_coeffs;max_coeffs;delta];
for person_index=1:40
for image_index=1:5
for block_index=1:52
blk_coeffs = myDatabase{2,person_index}{block_index,image_index};
min_coeffs = minmax(1,:);
delta_coeffs = minmax(3,:);
qt = floor((blk_coeffs-min_coeffs)./delta_coeffs);
myDatabase{3,person_index}{block_index,image_index} = qt;
label = qt(1)*10*7+qt(2)*7+qt(3)+1;
myDatabase{4,person_index}{block_index,image_index} = label;
end
myDatabase{5,person_index}{1,image_index} = cell2mat(myDatabase{4,person_index}(:,image_index));
end
end
TRGUESS = ones(7,7) * eps;
TRGUESS(7,7) = 1;
for r=1:6
TRGUESS(r,r) = 0.6;
TRGUESS(r,r+1) = 0.4;
end
EMITGUESS = (1/1260)*ones(7,1260);
fprintf('\nTraining ...\n');
for person_index=1:40
fprintf([myDatabase{1,person_index},' ']);
seqmat = cell2mat(myDatabase{5,person_index})';
[ESTTR,ESTEMIT]=hmmtrain(seqmat,TRGUESS,EMITGUESS,'Tolerance',.01,'Maxiterations',10,'Algorithm', 'BaumWelch');
ESTTR = max(ESTTR,eps);
ESTEMIT = max(ESTEMIT,eps);
myDatabase{6,person_index}{1,1} = ESTTR;
myDatabase{6,person_index}{1,2} = ESTEMIT;
if (mod(person_index,10)==0)
fprintf('\n');
end
end
fprintf('done.\n');
save DATABASE myDatabase minmax
I have attached my database
The error message that you posted is for a line of code that does not exist in this file, as it refers to myDatabase{1,person_index} in a line of code that in the source posted uses myDatabase{2,person_index}
The error trace that you posted would occur if
data_folder_contents = dir ('./data');
returned only the folders '.' and '..' and no other folders.

Connectez-vous pour commenter.

 Réponse acceptée

sruthi N
sruthi N le 14 Déc 2017
Modifié(e) : Walter Roberson le 14 Déc 2017
function for gendata
function [myDatabase,minmax] = gendata()
eps=.000001;
ufft = [1 5 6 8 10];
fprintf ('Loading Faces ...\n');
data_folder_contents = dir ('./data');
myDatabase = cell(0,0);
person_index = 0;
max_coeffs = [-Inf -Inf -Inf];
min_coeffs = [ Inf 0 0];
for person=1:size(data_folder_contents,1);
if (strcmp(data_folder_contents(person,1).name,'.') || ...
strcmp(data_folder_contents(person,1).name,'..') || ...
(data_folder_contents(person,1).isdir == 0))
continue;
end
person_index = person_index+1;
person_name = data_folder_contents(person,1).name;
myDatabase{1,person_index} = person_name;
fprintf([person_name,' ']);
person_folder_contents = dir(['./data/',person_name,'/*.pgm']);
blk_cell = cell(0,0);
for face_index=1:5
I = imread(['./data/',person_name,'/',person_folder_contents(ufft(face_index),1).name]);
I = imresize(I,[56 46]);
I = ordfilt2(I,1,true(3));
blk_index = 0;
for blk_begin=1:52
blk_index=blk_index+1;
blk = I(blk_begin:blk_begin+4,:);
[U,S,V] = svd(double(blk));
blk_coeffs = [U(1,1) S(1,1) S(2,2)];
max_coeffs = max([max_coeffs;blk_coeffs]);
min_coeffs = min([min_coeffs;blk_coeffs]);
blk_cell{blk_index,face_index} = blk_coeffs;
end
end
myDatabase{2,person_index} = blk_cell;
if (mod(person_index,10)==0)
fprintf('\n');
end
end
delta = (max_coeffs-min_coeffs)./([18 10 7]-eps);
minmax = [min_coeffs;max_coeffs;delta];
for person_index=1:40
for image_index=1:5
for block_index=1:52
blk_coeffs = myDatabase{2,person_index}{block_index,image_index};
min_coeffs = minmax(1,:);
delta_coeffs = minmax(3,:);
qt = floor((blk_coeffs-min_coeffs)./delta_coeffs);
myDatabase{3,person_index}{block_index,image_index} = qt;
label = qt(1)*10*7+qt(2)*7+qt(3)+1;
myDatabase{4,person_index}{block_index,image_index} = label;
end
myDatabase{5,person_index}{1,image_index} = cell2mat(myDatabase{4,person_index}(:,image_index));
end
end
TRGUESS = ones(7,7) * eps;
TRGUESS(7,7) = 1;
for r=1:6
TRGUESS(r,r) = 0.6;
TRGUESS(r,r+1) = 0.4;
end
EMITGUESS = (1/1260)*ones(7,1260);
fprintf('\nTraining ...\n');
for person_index=1:40
fprintf([myDatabase{1,person_index},' ']);
seqmat = cell2mat(myDatabase{5,person_index})';
[ESTTR,ESTEMIT]=hmmtrain(seqmat,TRGUESS,EMITGUESS,'Tolerance',.01,'Maxiterations',10,'Algorithm', 'BaumWelch');
ESTTR = max(ESTTR,eps);
ESTEMIT = max(ESTEMIT,eps);
myDatabase{6,person_index}{1,1} = ESTTR;
myDatabase{6,person_index}{1,2} = ESTEMIT;
if (mod(person_index,10)==0)
fprintf('\n');
end
end
fprintf('done.\n');
save DATABASE myDatabase minmax
I have also attached my Database

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by