From: Juraj on
Hello, can anyone help me? I have a program with input set of pictures. First it takes pictures and trains on them (face recognition). Then I need to randomly choose a picture and test it my program if it can match it with something in its memory. Is there any way/function/loop/command for random choosing of files? Thanks in advance
From: ImageAnalyst on
Juraj :
Use dir() to get your list of files, then use randperm() to go through
them in a random order.
From: Juraj on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <afd5cd6e-f46b-4f74-9990-2ef7bb2b5542(a)33g2000yqj.googlegroups.com>...
> Juraj :
> Use dir() to get your list of files, then use randperm() to go through
> them in a random order.

thanks, it worked almost as I needed. but I need only a few of those samples and I can't find out how to make it happen:) maybe with some for/while loop?

code looks like this so far:

[faceImages] = textread('faces\zoznam.txt', '%s');

face=[];
faces=[];
test_faces=[];

for i=1:length(faceImages)
str = strcat('faces\',faceImages{i});
[face]=imread(str);
[faceWidth,faceHeight]=size(face);
face=reshape(face,faceWidth*faceHeight,1);

for j=1:length([face])
faces(i,j) = face(j);
end

%for k=round(rand()*length([face])) %other approach, choosing random files
% test_faces(i,k) = face(k);
%end

for k=randperm(length([face])) %here I need only a part e.g. 20 random pictures
test_faces(i,k) = face(k);
%disp(k);
end

end




[Psi, Vecs, Features] = pc_train(faces, 9);
%[id] = pc_test(Psi, Vecs, Features, 9, testFace, idMap);
%[id_map_elem] = pc_test(Psi, Vecs, Features, 9, test_faces, id_map);
From: us on
"Juraj "
> for k=randperm(length([face])) %here I need only a part e.g. 20 random pictures
> test_faces(i,k) = face(k);
> %disp(k);
> end

one of the solutions

nf=randperm(numel(face));
for k=nf(1:20)
%
end

us
From: ImageAnalyst on
Juraj
So just use some of them. Look at this demo code:
Be sure to join that long fprintf() line which I'm sure the newsreader
will split into several lines.


ImageFiles = dir('c:/windows/*.*');
totalNumberOfFiles = length(ImageFiles)
scrambledList = randperm(totalNumberOfFiles);
numberIWantToUse = 5
loop_counter = 1;
for index = scrambledList(1:numberIWantToUse)
baseFileName = ImageFiles(index).name;
fprintf(1, 'File #%d = File #%d of original list = %s\n',
loop_counter, index, baseFileName);
loop_counter = loop_counter + 1;
end