matlab for experimental research
TRANSCRIPT
MATLAB for Experimental Research
Cont. PsychtoolboxDisplaying Images
Screen (cont’d)
See examples on the site for Screen
ScreenIntro.mScreenBlackWhite.mFunScreen.m
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
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
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
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
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)
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?
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 ?
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?
RandomPath.m