Contents
Present a drifting Gabor patch with cogent
demonstrates how to display a bitmap image using cg library Elliot Freeman 0207
gam = 2.2; % gamma value from calibration procedure contrast = .5; % contrast of gabor patch windowmode = 0; % 0: small window; 1: full screen horizontalResolution = 1024; % horizontal screen resolution in pixels: select from [640 800 1024 1152 1280 1600] imageFile = 'plaidMovie'; % filename of image matrix RGB = [1 0 1]; % maximum luminance of RGB guns (before scaling by overall contrast) contrast = 1; % overall contrast of images temporalFrequency = 0; % how many times movie is played per second refreshRate = 75; % refresh rate of screen in hertz trialDuration = 1000; % duration of each stimulus presentation (ms) ISI = 500; % inter stimulus interval (ms) fixPos = [0 0]; % X and Y position of stimulus stimPos = [0 100]; % X and Y position of stimulus fixSize = 5; % size of fixation point nTrial = 10; % number of trials escapeKey = 52; % code for escape key responseKeys = [97 98]; % codes for left and right-arrow keys speedMod = 5; % amount to modulate speed
load and describe movie matrix
load(imageFile, 'im1'); % load movie matrix load(imageFile, 'im2'); % load movie matrix [sX sY nFrames] = size(im1); % get dimensions and number of frames
Error using ==> load Unable to read file plaidMovie: No such file or directory.
computed constants
bg = .5 .^ (1/gam); % calculate gamma corrected mid-gray background value
start cogent
resVal = [640 800 1024 1152 1280 1600]; % possible screen resolutions resCode = find(horizontalResolution == resVal); % select one config_display(windowmode,resCode,[0 0 0], [bg bg bg]); % configure graphics window config_keyboard; % set up keyboard start_cogent; % start cogent keyMap = getkeymap;
make fixation sprite
fixSprite = 1000; cgMakeSprite(fixSprite, fixSize, fixSize, bg, bg, bg); % make a new sprite cgSetSprite(fixSprite); cgEllipse(fixPos(1), fixPos(2), fixSize, fixSize, [1 1 1], 'f'); cgSetSprite(0);
create each movie frame in a separate sprite
for iFrame = 1:nFrames % loop through frames imF1 = im1(:,:,iFrame); % extract frame from movie matrix imF2 = im2(:,:,iFrame); % extract frame from movie matrix % To load the images into sprites, Cogent needs a three column matrix: % each column contains the luminance values for Red Green and Blue % respectively. To make this matrix, % (1) transpose each image frame and % (2) scale each column by the appropriate values of RGB to manipulate % the colour of the resulting image imR = imF1' * RGB(1); % vector for red guns imG = imF1' * RGB(2); % vector for green guns imB = imF2' * RGB(3); % vector for blue guns % (3) now squash each R G or B image into a single column vector % - if you didn't transpose before, this operation results in 90deg rotation % (4) and horizontally concatenate into three column matrix imRGB0 = [imR(:) imG(:) imB(:)]; % now compile in to three-column matrix % finally apply overall contrast scaling, recenter values on 0.5, gamma correct imRGB0 = imRGB0 .* contrast; % apply contrast modulation to whole matrix imRGB1 = ( imRGB0 +1 ) /2; % convert values of -1->1 to 0->1 (gray is now .5) imRGB_gamma = imRGB1 .^ ( 1/ gam ); % apply gamma correction to image % make a new sprite and put image into it cgMakeSprite(iFrame, sX, sY, bg, bg, bg); % make a new sprite cgloadarray(iFrame, sX,sY,imRGB_gamma); % load image frame into sprite end
put up fixation and wait for any key
cgflip(bg, bg, bg); cgDrawSprite(fixSprite, fixPos(1), fixPos(2)); cgflip(bg, bg, bg); [ keyout, t, n ] = waitkeydown(inf); if keyout == escapeKey error('experiment aborted'); end
trial sequence
for iTrial = 1: nTrial %% random speed randSpeed = (rand(1) * speedMod) - (speedMod /2); %% work out how fast to play movie framesPerSecond = (temporalFrequency + randSpeed) * nFrames; % how many frames shown per second frameIncrement = framesPerSecond / refreshRate; % how much to increment frame count every screen refresh %% display movie t0 = time; iFrame = 0; while time < (t0 + trialDuration) iFrame = iFrame + frameIncrement; mFrame = mod(iFrame-1, nFrames)+1; cgDrawSprite(mFrame, stimPos(1), stimPos(2)); cgDrawSprite(fixSprite, fixPos(1), fixPos(2)); cgflip(bg, bg, bg); end cgDrawSprite(fixSprite, fixPos(1), fixPos(2)); cgflip(bg, bg, bg); wait(ISI); end stop_cogent