MATLAB Answers

error during selecting dynamically image from folder

3 views (last 30 days)
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 Comments
Balaji M. Sontakke
Balaji M. Sontakke on 9 Feb 2020
I want to randomaly select 8 images from specific folder how i can do that

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 9 Feb 2020
"I want to randomaly select 8 images from specific folder how i can do that"
Something like this:
P = 'path to the folder where the files are saved';
S = dir(fullfile(P,'*.bmp'));
N = numel(S);
X = randperm(N);
F = {S(X(1:8)).name} % cell array of 8 randomly selected filenames from that folder
  3 Comments
Balaji M. Sontakke
Balaji M. Sontakke on 9 Feb 2020
Its simply wow!!! hats of you sir, Great and thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!