How to display an image randomly
이전 댓글 표시
I am trying to display stimuli, but struggling as I am new to Matlab. How can I display stimuli (images) randomly from a folder in my documents? I want to use every image, but don't want to use the same picture more than once. Thanks
To be more clear, if I have an image in Documents --> Thesis --> Images how do I call this image to be displayed?
답변 (1개)
Use randperm to create a random ordering of your images. The code would go something like:
root = 'C:\somewhere\somefolder';
images = dir(fullfile(root, '*.png')); %or whatever extension you use
order = randperm(numel(images));
for idx = 1:numel(img)
currentimg = imread(fullfile(root, images(order(idx)).name));
imshow(currentimg);
%...
end
댓글 수: 3
Erin Krahn
2017년 10월 16일
Guillaume
2017년 10월 16일
Impossible to know because:
- "the screen just turned black and didn't do anything" is meaningless as a diagnostic. Surely, your whole computer monitor didn't turn black. And what did you expect the screen to do?
- we don't know what exact code you used. Note that the %... was meant for you to add whatever processing you wanted to do. If you were to use the code above without any modification then at the very least I would add a drawnow and a pause(1).
If the images do not display properly, you can replace the imshow call by
imshow(currentimg, []);
read the documentation of imshow to know the difference between the two syntax.
Walter Roberson
2017년 10월 16일
Also, add
drawnow() after the imshow()
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!