error during selecting dynamically image from folder
Afficher commentaires plus anciens
Error using randi
First input must be a positive scalar integer value IMAX, or two integer values [IMIN IMAX] with IMIN less than or
equal to IMAX.
Error in tt (line 25)
thisfile = files(randi(num_files)).name;
clc;
clear all;
tic;
%% Training images
id_test = 0;
id_train = 0;
for folder_idx = 1 : 10 % no of classes 100
for i = 1 : 8 % no of images per class 8
%thisfile = fullfile('ROITrain', num2str(folder_idx), [num2str(i) '.bmp ']);
files = dir( fullfile('ROITrain', num2str(folder_idx), [num2str(i) '.bmp ']));
num_files = numel(files);
thisfile = files(randi(num_files)).name;
%image = imread(filename);
B = imread(thisfile );
X = double(B);
X = imresize(X,[300 250],'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
save('db2.mat','reduced_traindata');
toc
2 commentaires
files is empty, so num_files is zero, which is not valid for randi.
But in any case it makes no sense to use dir with the actual name of a file:
dir( fullfile(..., [num2str(i) '.bmp ']));
It looks like the code mixes up the two main ways of processing multiple files:
Your code is very badly aligned. Badly aligned code is one way that beginners hide basic bugs in their code. I strongly recommend that you align your code consistently using the default MATLAB Editor settings. You can apply them to existing code by selecting all code text and pressing ctrl+i.
Balaji M. Sontakke
le 9 Fév 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Preview and Device Configuration dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!