matlab for experimental research

11
MATLAB for Experimental Research Cont. Psychtoolbox Displaying Images

Upload: others

Post on 25-Dec-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MATLAB for Experimental Research

MATLAB for Experimental Research

Cont. PsychtoolboxDisplaying Images

Page 2: MATLAB for Experimental Research

Screen (cont’d)

See examples on the site for Screen

ScreenIntro.mScreenBlackWhite.mFunScreen.m

Page 3: MATLAB for Experimental Research

Displaying images in PTB: PutImage

% Read in image just like usual>> myimg = imread('sungod','jpg');

% Use PutImage function

Try >> Screen PutImage?

>> Screen('PutImage', w, myimg);>> Screen('Flip',w);

See: PutImageExample.m

Page 4: MATLAB for Experimental Research

Displaying images in PTB: Texture

Preferred methodThe texture method is much faster and flexible compared to PutImage>> Screen MakeTexture?TextureIndex = Screen('MakeTexture', WindowIndex, imageMatrix, optional arguments…)

>> Screen DrawTexture?

See: TextureExample.m

Page 5: MATLAB for Experimental Research

Textures% Read in image just like usualmyimg = imread(’sungod','jpg');

% make texture, nothing happens on screen.% this just prepares the image as texture on % offscreen window

mytex = Screen('MakeTexture', w, myimg);

Screen('DrawTexture', w, mytex); Screen('Flip',w);

Note where the image displays

See: TextureExample.m

Page 6: MATLAB for Experimental Research

ImageAndTexture.m

Simple code that displays the same image with both methodsIf location is not specified, it will default to the center of the screen

Page 7: MATLAB for Experimental Research

Textures, Screen, Window

What’s the difference between window, screen and texture?https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ:-Textures,-Windows,-Screens

For more PTB notes, info, etc see file on the site called PTB_Notes.pdf (and also PTB_AdditionalNotes.pdf)

Page 8: MATLAB for Experimental Research

Displaying in Specific Locations

� Let’s display an image on different locations on Screen.

� Download TextureTwoLocations.m and sungod.jpgfrom the class website and run the m file.

� Image is displayed first on the left and then on the right of the screen. And then both.

� Do you understand how we can specify where can display an image?

� Why do we see text and the images together only in the last part?

Page 9: MATLAB for Experimental Research

Images at different locations on screen

� PutImage and DrawTexture both require a location for the image as an input argument.

� We need to calculate the coordinates of where we want to put your image (use your geometry knowledge).

� Start by calculating the coordinates of the center of the screen.

>> help RectCenter

� Then, calculate the coordinates of the image location relative to the center based on the image size

� Do you understand what is happening in lines 40-41 of TextureTwoLocations.m ?

Page 10: MATLAB for Experimental Research

Moving stimuli� Movies can be made by changing the position of

the stimulus each frame

� Exercise: Draw a circle that moves randomly on screen without any of it crossing the top, bottom, left and right borders of the screen.

� How can you do that? Any ideas?

Page 11: MATLAB for Experimental Research

RandomPath.m