How to present many images repeatedly and randomly? Problem Function
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
Matlab is still a new language to me and I would like to present 360 experimental trials based on 40 images (I want those images to be repeated and it should be presented randomly). I created the following Function but none of the parts works correctly :( Anybody to help?
% X
%This function is created to test the EGI system. Faces will be presented, half
%will be inverted.
function X
Screen('Preference', 'SkipSyncTests', 1)
%Open the screen
[wPtr,rect]=Screen('OpenWindow',max(Screen('Screens')),[0 0 600 600]);
xCenter=rect(3)/2;
yCenter=rect(4)/2;
imgPath = 'C:/Users/X/Desktop/MatlabTutorial/EGItest';
imgType = '*.jpeg';
images = dir(fullfile(['C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg']));
%Create textures
for n=1:20
images{n}=imread(sprintf('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg'));
end
imageData=imread('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg');
imageTexture=Screen('MakeTexture', wPtr,imageData);
%Get size of image (all images the same size in this example)
%imageHeight
%imageWidth
%colorChannels
[imageHeight, imageWidth,colorChannels]=size(imageData);
%Set up left and right picture locations
gap=100; %distance of pics from center
leftRect=[xCenter-gap-imageWidth, yCenter-imageHeight/2, xCenter+imageHeight/2];
rightRect=[xCenter+gap, yCenter-imageHeight/2, xCenter+gap+imageWidth, yCenter+imageHeight/2];
%set up some vectors with our options
allFiles=dir('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg');
allNames={allFiles.jpeg};
textures=[imageTexture];
textureNames={'allFiles'};
rects={leftRect, rightRect};
rectNames={'left', 'right'};
%loop for 200 trials
for trial=1:200
file_name=dir(strcat('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg'));
im=imread(strcat('C:/Users/X/Desktop/MatlabTutorial/EGItest','*.jpeg'));
imtool(im);
repelem(v,3);
end
%pick a random number 1 or 2
randTextureNum=randi(2);
%now use that number tp pick a texture
ourTexture=textures(randTextureNum);
%draw the pie
%windowPtr=wPtr
Screen('DrawTexture', wPtr, ourTexture,[], ourRect);
stimTime=Screen('Flip', wPtr);
end
댓글 수: 0
채택된 답변
Walter Roberson
2015년 8월 7일
images_info = dir(fullfile(imgPath, imgType));
numImage = length(images_info);
images = cell(numImage,1);
for K = 1 : numImage
images{K} = imread( fullfile(imgPath, images_info(K).name) );
end
To go further we need to know how you want the 9 copies of each of the 40 images to be presented relative to each other. Do you want all 40 images once each in a random order, and then the same order repeated another 8 times? Do you want all 40 images once each in a random order, and then the 40 images once each in a different random order, and so on, each time changing the order of the group of 40? Do you want the order to be completely randomized as long as each of the 40 is shown 9 times exactly? So the first image might again be shown as the 17th image and again the 23rd image and then might not show up for another 100 images? Do you want the oder to be completely randomized but the same image cannot show up within some number N of the previous time? Are you doing 9 different things for each image that need to be tracked? Is the first thing done on the first cycle of 40, the second thing done on the second cycle of 40, and so on? Or should the order of the different things for each image be random?
imagenum = 1:40;
thingnum = 1:9;
[IMAGENUM, THINGNUM] = ndgrid(imagenum, thingnum);
pair_specs = [IMAGENUM(:), THINGNUM(:)];
randorder = randperm(size(pair_specs,1));
rand_specs = pair_specs(randorder,:);
댓글 수: 4
Walter Roberson
2015년 8월 7일
Please go back and incorporate the style I showed at the beginning of my Answer, the code before "To go further". That is, do not keep reading the files, do not hardcode the directories, use fullfile().
Also you are going to need to say what problem you are encountering. You have not admitted yet that you are using the psychtools toolbox; I do not have that package installed.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!