How can I pull a random image to display, from a folder of images using Psychtoolbox?
4 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to show an image, randomly selected from a folder of images. I'm using Psychtoolbox. How do I instruct it to pull an image randomly from the folder, to display on the screen? The images can be used more than once.
Thanks!!
0 个评论
采纳的回答
Orion
2014-11-4
编辑:Orion
2014-11-4
I don't know this toolbox (not sure a lot of people do).
but in a general way, with matlab, you can do something like
% get all images (here all *.jpg found in the current directory, but you can specify the format you want)
MyImages = dir(fullfile(pwd,'*.jpg'));
% generate a random number between 1 and the number of images
RandomNumber = randi([1 size(MyImages,1)]);
% get the corresponding name of the image
MyRandomImage = MyImages(RandomNumber).name;
% display the image
image(imread(MyRandomImage));
0 个评论
更多回答(1 个)
Sean de Wolski
2014-11-4
Perhaps use randi to generate a random index between 1 and the number of files.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image display and manipulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!