error occured during selection of random images

1 Ansicht (letzte 30 Tage)
Balaji M. Sontakke
Balaji M. Sontakke am 13 Feb. 2020
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

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 13 Feb. 2020
Bearbeitet: KALYAN ACHARJYA am 13 Feb. 2020
Beacuse length of F / fullfile total images is less than 10, check and verify
  6 Kommentare
KALYAN ACHARJYA
KALYAN ACHARJYA am 13 Feb. 2020
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 am 13 Feb. 2020
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?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by