Contents
% cgGammaDemo_directColour.m % Demo of how to gamma correct an image and display it using direct colour % mode % using the Cogent Graphics library % Download it at http://www.vislab.ucl.ac.uk/CogentGraphics/index.html
Stimulus Parameters
gammaValue = 2.2; freq = 5; % frequency of grating sz = 126; % size in pixels
define grating
x0 = linspace(0,2*pi,sz); % linear sequence 0:2*pi x1 = sin(x0 * freq); % create sine wave with values -1:1 x = (x1 +1) /2; % convert values to 0:1
convert into 2D image
im0= meshgrid(x)'; % uncorrected image imG = im0 .^ (1/gammaValue); % gamma-corrected transformation
Initialize cogent graphics
cgloadlib; % load graphics library cgopen(1,8,0,0); % create small window cgfont('Helvetica', 18) cgpencol(1,1,0);
Show uncorrected image
imRGB = repmat(im0(:), 1,3); % create separate columns for red green and blue cgloadarray(1,sz,sz,imRGB); % load graylevels into sprite 1 cgdrawsprite(1,-100,0); % put sprite into back buffer cgtext('Uncorrected',-100,-100); % label
show corrected image
imRGB = repmat(imG(:), 1,3); % create separate columns for red green and blue cgloadarray(1,sz,sz,imRGB); % load graylevels into sprite 1 cgdrawsprite(1,100,0); % put sprite into back buffer cgtext('Corrected',100,-100); cgflip; % switch back buffer to front (i.e. make visible)