Presenting random images from a file, where each image is presented only once?

7 ビュー (過去 30 日間)
Robert Newman
Robert Newman 2019 年 5 月 9 日
コメント済み: Jeff Miller 2019 年 5 月 10 日
Hi,
This is my fourth day of coding ever so bear with me.
Right now I have a folder with images. I want to present each image from the folder randomly once and only once for a certain number of trials.
So far my code looks like this. It successfully presents a random image from the folder, but it can use the same images over again which I don't want.
How do I make it so that each image in the folder is displayed once and only once?
Thank you in advance for your help!
emotionalImageDirectory = 'C:\PsychExperiment\Emotional';
imageTwoVarOne = dir([emotionalImageDirectory '\*.jpg']);
imageTwoVarTwo = numel(imageTwoVarOne);
idx = randi(imageTwoVarTwo);
loadimageTwo = imread(imageTwoVarOne(idx).name);

採用された回答

Jeff Miller
Jeff Miller 2019 年 5 月 10 日
Store a random sequence of the images in advance and then cycle through them one by one. Something like this,
emotionalImageDirectory = 'C:\PsychExperiment\Emotional';
imageTwoVarOne = dir([emotionalImageDirectory '\*.jpg']);
imageTwoVarTwo = numel(imageTwoVarOne);
imageseq = randperm(imageTwoVarTwo);
for i=1:imageTwoVarTwo % or the number of trials you want, which may be less than the n of images
idx = imageseq(i);
loadimageTwo = imread(imageTwoVarOne(idx).name);
end
  2 件のコメント
Robert Newman
Robert Newman 2019 年 5 月 10 日
Thank you! What if I wanted to present two images at the same time? Let's say I had another subfolder with non-emotional images, and I wanted them to also be presented once and only once and in a random order. I've tried using a nestled for loop with the break function, but so far this hasn't worked. i.e. something like
emotionalImageDirectory = 'C:\PsychExperiment\Emotional';
imageTwoVarOne = dir([emotionalImageDirectory '\*.jpg']);
shuffleImagesTwo = randperm(numel(imageTwoVarOne));
for b =1:shuffleImagesTwo
loadimageTwo = imread(imageTwoVarOne(b).name);
break
end
Jeff Miller
Jeff Miller 2019 年 5 月 10 日
Not sure that I follow, but maybe you want two random sequence holders, something like this:
emotionalImageDirectory = 'C:\PsychExperiment\Emotional';
imageTwoVarOne = dir([emotionalImageDirectory '\*.jpg']);
imageTwoVarTwo = numel(imageTwoVarOne);
imageseq = randperm(imageTwoVarTwo);
nonemotionalImageDirectory = 'C:\PsychExperiment\NonEmotional';
nonemoimageTwoVarOne = dir([nonemotionalImageDirectory '\*.jpg']);
nonemoimageTwoVarTwo = numel(nonemoimageTwoVarOne);
nonemoimageseq = randperm(nonemoimageTwoVarTwo);
for i=1:ntrials
idxemo = imageseq(i);
idxnonemo = nonemoimageseq(i);
loadimageTwo = imread(imageTwoVarOne(idx).name);
nonemoloadimageTwo = imread(nonemoimageTwoVarOne(idx).name);
% Now display the two images for this trial?
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage display and manipulation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by