Experiment with a random presentation of images from a folder

Hi everyone, I'm new to matlab. I am trying to create a script for my experiment. The script should consist in the presentation on the screen of 40 images showing emotional faces (with 3 different emotions: neutral, happy, angry) from a folder called "images.experiment". These images must be presented randomly without repeating themselves in a loop which is repeated 3 times. After each image I should make an assessment of the intensity ("how emotional is the stimulus you see?") of the emotion in the image on a Likert scale from 1 to 9. Finally I have to save every answer (according to the condition/image) of each subject on an excel document. Can someone help me? I am using Psychtoolbox on Window. Thanks everyone in advance.

4 Comments

What are the constraints on the presentation of the images? If an image is shown then how long until it can be shown again? Do you need to show all the images through as a set before any image is shown again, or for example could a particular image be shown 5th and 32nd as long as the total number of repeats is 3 by the end? Is it allowed that the first image shown could also be the first image of the second repeat?
images should be presented in the center of the screen for 200ms. Before the image I should present a fixation point for 200ms and after the image I should present a mask for 200ms (fixation point and mask have both been saved as images in the same folder of all the 40 images/stimuli). The order of the images in each set od the loop is not important as long as they are random. And yes the first image shown could also be the first image of the second repeat.
randperm(40) three times to get the order of presentation. The rest about showing an image at a particular location for a particular time is really psychtoolbox functions not MATLAB. Functions to get input with timing is also psychtoolbox
Yes the fact is that I'm currently using Psychtoolbox

Sign in to comment.

 Accepted Answer

http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F shows how you can read a series of files. assign them into a cell array. Then
numfiles = numel(YourCellArray);
order_to_show = [randperm(numfiles), randperm(numfiles), randperm(numfiles)];
Now do whatever psychtoolbox requires you to do in order to set up the screen. Then you would do something similar to
for K = 1 : numel(order_to_show)
this_image = YourCellArray{order_to_show(K)};
do whatever psychtoolbox needs to present the fixation point for the given time
do whatever psychtoolbox needs to present this_image for the given time
do whatever psychtoolbox needs to present the mask for the given time
do whatever psychtoolbox needs to retrieve the user input
responses(K) = user response
end
results = table(order_to_show(:), responses(:), 'VariableNames', {'ImageNumber', 'Response'});
writetable(results, 'FileNameToWriteTo.xlsx');
You might modify the results table slightly if you wanted to write in the image name instead of the image number (index), something like
results = table(ImageNames(order_to_show(:)), responses(:), 'VariableNames', {'ImageName', 'Response'});

3 Comments

If I recall correctly, in practice, for more precise timing, instead of displaying each image by array at the appropriate time, at the time you read the images in, you would generate a Psychtoolbox "texture", and at the appropriate time you would tell psychtoolbox to display the "texture".
A texture is an image that Psychtoolbox has pre-processed somehow.... possibly stored into separate memory carefully aligned on physical memory boundaries so that when it comes time to display the image, Psychtoolbox can just update pointers... some implementation details like that.
All the details about presenting for a given time or fetching user input, are using Psychtoolbox supplied functions. Psychtoolbox has its own support forum. The details are not really appropriate here since they are third-party functions not supplied as part of Mathworks products.
try
Screen('Preference', 'SkipSyncTests', 1);
% Open window with default settings:
myWindow=Screen('OpenWindow', 0, 127);
% Specify the folder where the files live.
myFolder = 'C:\Users\clari\OneDrive\Desktop\MATLAB\im.prova';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
numfiles = numel(imageArray);
order_to_show = [randperm(numfiles), randperm(numfiles), randperm(numfiles)];
for K = 1 : numel(order_to_show)
this_image = imageArray(order_to_show(K));
texture(K)=Screen('MakeTexture',myWindow,this_image);
end
for K= 1:numel(order_to_show)
Screen('DrawTexture',myWindow,texture(K))
Screen('Flip',myWindow);
%wait
WaitSecs(0.2)
end
%close the screen
sca;
catch
%#ok<*CTCH>
% This "catch" section executes in case of an error in the "try"
% section []
% above. Importantly, it closes the onscreen window if it's open.
sca;
fclose('all');
psychrethrow(psychlasterror);
end
I'm tryng doing this but it doesn't work and when I run this, MATLAB crashes completely

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!