Download presentation
Presentation is loading. Please wait.
1
The Psychophysics Toolbox
In Matlab
2
What Is It? Originally created by Brainard (1997) and Pelli (1997).
Allows Matlab to control the entire display with microsecond timing. Multiple displays can be controlled at the same time (e.g. for stereoscope setups). Routines implemented to allow response collection. Implements a method for adaptive threshold measurement (i.e. the QUEST procedure). Available from:
3
The Basics % Ignore synchronization tests Screen('Preference', 'SkipSyncTests', 1); % Open a pointer in video memory ScreenNum = 0; [windowPtr,Rect] = Screen('OpenWindow', ScreenNum); % Make an image [x,y] = meshgrid(1:Rect(3),1:Rect(4)); r = hypot(x-(Rect(3)+1)/2,y-(Rect(4)+1)/2); Img = cos(2*pi*r/20)* ; % Writes the image to video memory Screen('PutImage', windowPtr, Img); % Transfers the image from video memory to the monitor Screen('Flip', windowPtr); % Waits for the user to press a key KbWait; % Closes all windows Screen('CloseAll');
5
Line-By-Line Cathode Ray Tube Liquid Crystal Display
Screen('Preference', 'SkipSyncTests', 1); CRT monitors fill in pixels row- wise starting from the top-left and going to the bottom-right. When the bottom-right is reached, the monitor sends a screen refresh signal, letting the computer know it’s ready to start a new image. The psychophysics toolbox has the option of synchronizing images to this signal. LCD monitors draw all pixels at the same time, and do not send synchronization signals. Thus, when using a LCD monitor, this line should be included at the beginning of your code so that the psychophysics toolbox does not try wait for a screen refresh to draw an image.
6
Line-By-Line ScreenNum = 0;
When multiple displays are connected to the video card, they may be used individually, or in combination. The screen number for the displays are as follows: 0 = All available displays combined. 1 = Primary display only. 2 = Secondary display only. ScreenNum = 1; ScreenNum = 2;
7
Line-By-Line [windowPtr,Rect] = Screen('OpenWindow', ScreenNum);
Creates a pointer to space in video memory where images may be written. Returns the pointer (windowPtr) and the size of the screen (Rect = [left top right bottom]).
8
Line-By-Line [x,y] = meshgrid(1:Rect(3),1:Rect(4));
Creates a Cartesian coordinate system over the image. E.g. 𝑥= , 𝑦= The point (x = 2, y = 1) is indexed using x(1,2), y(1,2).
9
Line-By-Line r = hypot(x-(Rect(3)+1)/2,y-(Rect(4)+1)/2);
Calculate the radius from the center of the image. hypot(x,y) calculates 𝑥 2 + 𝑦 2 Taking x-(Rect(3)+1)/2 and y-Rect(4)+1)/2 centers the coordinate system on the middle of the image. E.g. 𝑥= −1 0 1 −1 0 1 − , 𝑦= −1 −1 −
10
Line-By-Line Img = cos(2*pi*r/20)*128+128;
Creates an image that is the cosine of the radius, with a period of 20 pixels. Img = cos(2πr/20)× Period y = cos(x) 1 250 200 0.5 150 100 -0.5 50 90 180 270 360 450 540 630 720 20 40 60 80 100
11
Line-By-Line Screen('PutImage', windowPtr, Img);
Writes the image to video memory Screen('Flip', windowPtr); Transfers the image from video memory to the monitor
12
Line-By-Line KbWait; Stops the program until the user makes a keypress. Screen('CloseAll'); Clears the monitor and the video memory.
13
Getting Help With The Psychophysics Toolbox
Normal Matlab functions: help imwrite help meshgrid Psychophysics Toolbox functions: Screen CloseAll? Screen OpenWindow? Screen Flip? Start with the word Screen, then a space, then the name of the function, then a question mark.
14
Listing All Psychophysics Toolbox Functions
To list all available Psychophysics Toolbox functions type “Screen” at the command window: Screen
15
Showing Movies % Ignore synchronization tests Screen('Preference', 'SkipSyncTests', 1); % Open a pointer in video memory ScreenNum = 0; [windowPtr,Rect] = Screen('OpenWindow', ScreenNum); % Prepare some image creation variables [x,y] = meshgrid(1:Rect(3),1:Rect(4)); r = hypot(x-(Rect(3)+1)/2,y-(Rect(4)+1)/2);
16
Showing Movies (continued)
% Generate the frame textures nFrm = 100; Texture = zeros(nFrm,1); for iFrm = 1:nFrm Img = cos(2*pi*r/20 - 2*pi*iFrm/nFrm)* ; Texture(iFrm) = Screen('MakeTexture', windowPtr, Img); end Screen('PreloadTextures', windowPtr);
17
Showing Movies (continued)
for iFrm = 1:nFrm % Draw the image in video memory Screen('DrawTexture', windowPtr, Texture(iFrm)); % Transfer the image from video memory to the screen Screen('Flip', windowPtr); end % Close all windows and clear video memory Screen('CloseAll');
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.