How to solve Index exceeds matrix dimensions problem?

1 回表示 (過去 30 日間)
sruthi N
sruthi N 2017 年 12 月 14 日
コメント済み: Walter Roberson 2017 年 12 月 14 日
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 件のコメント
sruthi N
sruthi N 2017 年 12 月 14 日
編集済み: Walter Roberson 2017 年 12 月 14 日
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
Walter Roberson
Walter Roberson 2017 年 12 月 14 日
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.

サインインしてコメントする。

採用された回答

sruthi N
sruthi N 2017 年 12 月 14 日
編集済み: Walter Roberson 2017 年 12 月 14 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePoint Cloud Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by