error occured during selection of random images

조회 수: 1 (최근 30일)
Balaji M. Sontakke
Balaji M. Sontakke 2020년 2월 13일
댓글: Balaji M. Sontakke 2020년 2월 13일
Index exceeds matrix dimensions.
Error in tt (line 18)
fn = fullfile(P,D,F{ii});
clc;
clear all;
tic;
%% Training images
id_test = 0;
id_train = 0;
P = 'ROIBintrain'; % i.e. relative/absolute path to where the subfolders are.
for ii = 1:10 % no of classes
D = sprintf('%u',ii);
S = dir(fullfile(P,D,'*.bmp')); % get all filenames in subfolder
N = numel(S);
X = randperm(N);
F = {S(X(1:8)).name}; % randomly select 8 filenames.
for jj = 1:numel(F) % no of images per class
fn = fullfile(P,D,F{ii});
im = imread(fn);
X = double(im);
X = imresize(X,[100 120],'bilinear'); %300 250
id_train = id_train+1;
traindata{id_train}=ext_vein(X,1);
traindata = traindata';
% only four minutie is taken from one image
reduced_traindata = cellfun(@(M) M(1:min(end,4), :), traindata, 'uniform', 0);
end
end
%% Testing images
d=[];
P = 'ROIBintrain'; % i.e. relative/absolute path to where the subfolders are.
for ii = 1:10 % no of classes
D = sprintf('%u',ii);
S = dir(fullfile(P,D,'*.bmp')); % get all filenames in subfolder
N = numel(S);
X = randperm(N);
F = {S(X(1:8)).name}; % randomly select 8 filenames.
for jj = 1:numel(F) %no of images per class
fn = fullfile(P,D,F{ii});
im = imread(fn);
X = double(im);
X = imresize(X,[100 120],'bilinear'); %300 250
id_test = id_test+1;
testdata{id_test}=ext_vein(X,1);
testdata = testdata';
% only four minutie is taken from one image
reduced_testdata = cellfun(@(M) M(1:min(end,4), :), testdata, 'uniform', 0);
end
end
%%
save('db1.mat','reduced_testdata');
save('db2.mat','reduced_traindata');
toc

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 2월 13일
편집: KALYAN ACHARJYA 2020년 2월 13일
Beacuse length of F / fullfile total images is less than 10, check and verify
  댓글 수: 6
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 2월 13일
In the initial for loop you have defined ii = 1:10, when ii reached to 9, how it gets the F{9}, its having length only 8, hence it shows the error in that line, change the ii to 8, may be it works (to test)
Error in tt (line 18)
fn = fullfile(P,D,F{ii});
Balaji M. Sontakke
Balaji M. Sontakke 2020년 2월 13일
no sir there is no effect. ii indicates 10 folders each folder having 8 images, i want 5 images randmly from each folder, this program read 5 images but stop with error why this so?

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by