sca;
close all;
clear;
PsychDefaultSetup(2);
screens = Screen('Screens');
screenNumber = max(screens);
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = white / 2;
inc = white - grey;
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey);
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
ifi = Screen('GetFlipInterval', window);
[xCenter, yCenter] = RectCenter(windowRect);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
theImageLocation = [PsychtoolboxRoot 'PsychDemos' filesep...
'AlphaImageDemo' filesep 'konijntjes1024x768.jpg'];
theImage = imread(theImageLocation);
[s1, s2, s3] = size(theImage);
if s1 > screenYpixels || s2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
imageTexture = Screen('MakeTexture', window, theImage);
gaussDim = 50;
gaussSigma = gaussDim / 3;
[xm, ym] = meshgrid(-gaussDim:gaussDim, -gaussDim:gaussDim);
gauss = exp(-(((xm .^2) + (ym .^2)) ./ (2 * gaussSigma^2)));
[s1, s2] = size(gauss);
mask = ones(s1, s2, 2) * grey;
mask(:, :, 2) = white * (1 - gauss);
masktex = Screen('MakeTexture', window, mask);
fullWindowMask = Screen('MakeTexture', window,...
ones(screenYpixels, screenXpixels) .* grey);
[xg, yg] = meshgrid(-3:1:3, -3:1:3);
spacing = gaussDim * 2;
xg = xg .* spacing + screenXpixels / 2;
yg = yg .* spacing + screenYpixels / 2;
xg = reshape(xg, 1, numel(xg));
yg = reshape(yg, 1, numel(yg));
dstRects = nan(4, numel(xg));
for i = 1:numel(xg)
dstRects(:, i) = CenterRectOnPointd([0 0 s1, s2], xg(i), yg(i));
end
Screen('DrawTextures', fullWindowMask, masktex, [], dstRects);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('DrawTexture', window, fullWindowMask);
Screen('Flip', window);
KbStrokeWait;
sca;