Docsity

Change Blindness Experiment: A MATLAB-based Assignment - Prof. Joh Calandrino, Assignments of Computer Science

Toggle sidebar
bg1
COMP 116
November 12, 2007
Assn #7: Change blindness, Due Nov 30
In this assignment, the amount of code you have to write is small, but it has to interact
with MATLAB's mechanisms for user interfaces.
Write a program that will allow you to experiment with the parameters of change
blindness, as demonstrated by Rensink et al. http://www.psych.ubc.ca/~rensink/flicker/
What timings make change detection hard? Are some changes easier to detect than others? Are
some people consistently take longer than others? Do people learn as they see more examples?
Your program should take a list of pairs of images, and put the pairs in random order.
Then it will give a user 60 or 120 seconds to detect the change in each pair by showing each
image for a chosen amount of time (say 0.5, 1, 1.5, or 2.5 seconds) , followed by a gray, black, or
white screen for a chosen amount of time (say 0, 0.08, 0.1, 0.15, 0.25 secs). The user presses a
key when they detect the change, and the program records the time with the experimental
parameters (including chosen times, image, & image order) and maybe some user parameters
(gender, age, tiredness) which you can ask for.
To break this into smaller pieces:
1. Start a timer…
The timer is easy: tic; starts the timer and t = toc; sets t to the number of seconds between
tic and toc. (Without the semicolon, toc will print the time.)
2. …that you can read when a key on the keyboard is pressed.
More interesting is to get MATLAB to respond when a key is pressed, even if it is busy doing
other things – this is the issue faced by any GUI (Graphical User Interface). MATLAB (and many
other systems that support GUIs, including Java, Visual Basic/C++, and .NET) use callback
functions; small functions that you write, and then register with the system so that they are called
on some user interface event (key or button press, mouse click or drag, etc.)
If you write the following function myfig:
function myfig(src,evnt)
% callback function for keypress in figure window
clf; toc % clear figure & display time since tic
And then type the following in MATLAB:
figure('KeyPressFcn',@myfig); imagesc(magic(8)); tic;
Then when you press a key, MATLAB will blank the figure and print the time.
Global variables (see doc global): I’ve mentioned these before saying I didn’t want to teach them,
but now is the time… You can have a variable foo that can be accessed by several functions if at
the top of your script and each function you say global foo. This is to be avoided if possible,
but sometimes you need a callback function to set something like gKeyPressed = true; to indicate
that a key has been pressed.
3. Show images…
For most images, you just x = imread(filename); image(x); axis image; (axis image
makes each pixel square on the screen.)
pf2

Partial preview of the text

Download Change Blindness Experiment: A MATLAB-based Assignment - Prof. Joh Calandrino and more Assignments Computer Science in PDF only on Docsity!

COMP 116

November 12, 2007

Assn #7: Change blindness, Due Nov 30

In this assignment, the amount of code you have to write is small, but it has to interact

with MATLAB's mechanisms for user interfaces.

Write a program that will allow you to experiment with the parameters of change

blindness, as demonstrated by Rensink et al. http://www.psych.ubc.ca/~rensink/flicker/

What timings make change detection hard? Are some changes easier to detect than others? Are

some people consistently take longer than others? Do people learn as they see more examples?

Your program should take a list of pairs of images, and put the pairs in random order.

Then it will give a user 60 or 120 seconds to detect the change in each pair by showing each

image for a chosen amount of time (say 0.5, 1, 1.5, or 2.5 seconds) , followed by a gray, black, or

white screen for a chosen amount of time (say 0, 0.08, 0.1, 0.15, 0.25 secs). The user presses a

key when they detect the change, and the program records the time with the experimental

parameters (including chosen times, image, & image order) and maybe some user parameters

(gender, age, tiredness) which you can ask for.

To break this into smaller pieces:

  1. Start a timer… The timer is easy: tic; starts the timer and t = toc; sets t to the number of seconds between tic and toc. (Without the semicolon, toc will print the time.)
  2. …that you can read when a key on the keyboard is pressed. More interesting is to get MATLAB to respond when a key is pressed, even if it is busy doing other things – this is the issue faced by any GUI (Graphical User Interface). MATLAB (and many other systems that support GUIs, including Java, Visual Basic/C++, and .NET) use callback functions ; small functions that you write, and then register with the system so that they are called on some user interface event (key or button press, mouse click or drag, etc.) If you write the following function myfig: function myfig(src,evnt) % callback function for keypress in figure window clf; toc % clear figure & display time since tic And then type the following in MATLAB: figure('KeyPressFcn',@myfig); imagesc(magic(8)); tic; Then when you press a key, MATLAB will blank the figure and print the time. Global variables (see doc global): I’ve mentioned these before saying I didn’t want to teach them, but now is the time… You can have a variable foo that can be accessed by several functions if at the top of your script and each function you say global foo. This is to be avoided if possible, but sometimes you need a callback function to set something like gKeyPressed = true; to indicate that a key has been pressed.
  3. Show images… For most images, you just x = imread(filename); image(x); axis image; (axis image makes each pixel square on the screen.)
  1. for a given amount of time… using movie (See doc movie) MATLAB has a movie command that can show specified frames at a specified speed for a given time. This is the easiest way, and should work on even very slow computers. (The only drawback is that the movie plays to completion even if the user presses a key; maybe someone can find a way around this.) You can capture any set of figures as frames: for example to get 10 plots as 10 frames, x = 0:.01:pi; for i = 1:10; plot(x, sin(x*i)); F(i)=getframe; end %Now, you can show these as a movie at by running through them 12 times at 5 frames per sec: movie(F, [12 1:10 9:-1:2], 5); If your program first captures a gray and a black screen as F(1) and F(2), and then displays each image and captures as F(i) for i=3…, then you could change between 5 and 6 at .5 sec each, showing black for .1 sec, with movie(F, [50 5 5 5 5 5 2 6 6 6 6 6 2], 10); Here, the 50 repetitions give a total of 60 seconds. Note that you would want to capture frames when the user isn't looking. You could consider capturing the frames once and saving them as a .mat file that you could just load at the beginning of your program.
  2. Or… Use a modified version of the movie function: mymovie (Read 4. first) I made a version of movie that will abort if the global variable gKeyPressed is ever true. (see 2.) It also allows you to specify fps as a vector giving the number of seconds per frame in the list of frames. The code is in the zip file with the figures online.
  3. Or… Show images for a given amount of time using timer There is a timer function that can set a callback to run every certain number of seconds so that you can have complete control, and stop the experiment when the user presses a key. You could use image( ) to display, but a better, flicker-free way is to use handle graphics and double buffering. (See MATLAB documentation on graphics and/or talk to me if you are interested in advanced animation.)
  4. Produce output. You can open a file for 'append' and add information on experiments using fprintf (see previous worksheet, doc fprintf, or Gilat). If you separate data by tabs (\t), then it can easily be read into a spreadsheet. For example, this opens a file and adds a line containing subject name, image #, order #, image and blank times, blank color, and time taken in seconds. You can add as many lines as you want with other fprintf lines between the fopen and fclose. fid = fopen('cdexperiment.data', 'a'); % 'a' opens for append fprintf(fid, '%s\t%d\t%d\t%f\t%f\t%d\t%f\n', subjectnamestring, imagenumber, imageordernumber, imagetime, blanktime, blankcolor, timetaken); fclose(fid);

In this assignment, I make an exception to my usual rule that whatever you turn in must be your

own typing: you are encouraged to work with partners so that one person does the keypress

function, another does the image display, and another does the experiment setup or data capture,

and you may all turn in the same program.

Images are available online, or you are welcome to make your own with any image editor. Matlab

reads most image formats (gif, jpeg, png, tiff).