Changing White and Black Background not resulting in Gray

Hello,

I would like to change contrast between the colours black and white on every frame. Theoretically, the resulting presentation should be a solid gray, as the colour is switching between black and white every frame. However, the result is a more kind of blue tone.
I wanted to try it for the DrawDots, however I realised the problem also occurs when drawing to the whole screen (see code). Did anyone find a solution for that or has a suggestion how to improve timing? Or is it simply not possible with Psychtoolbox. I already found a similar question in the forum here, however that was 10 years ago. Maybe there have been changes :)?

Problem occurs on MATLAB R2020b, Windows 10, 240 HZ Screen (However, I also changed to Mac OS Sierra, CAD Monitor, HDMI conncetor etc.)…

  vbl = Screen('Flip', wPtr);
    

% ptp settings
Screen('Preference', 'SkipSyncTests', 0);
AssertOpenGL;
KbName('UnifyKeyNames');
screens   = Screen('Screens');
screenNum = max(screens);
[wPtr, rect] = Screen('OpenWindow', screenNum);
ifi          = Screen('GetFlipInterval', wPtr);
topPriorityLevel = MaxPriority(wPtr);
frameRate    = Screen('FrameRate', screenNum);
HideCursor;
white = WhiteIndex(screenNum);
black = BlackIndex(screenNum);
grey  = round((white+black)/2);
inc   = white-grey;             % contrast range for given white and grey values
Screen('FillRect', wPtr, grey)
Screen('TextSize', wPtr , 15);
Screen('Flip', wPtr);
[X,Y] = RectCenter(rect);

% Get the size of the on screen window in pixels
[screenXpixels, screenYpixels] = Screen('WindowSize', wPtr );

%% Paramters for Screen
movieDurationSecs   = 1.5;  %1.5
movieDurationFrames = round(movieDurationSecs * frameRate);


%% TRIAL-LOOP
for count = 1:nTrials 
    
    FlushEvents;
    tex = [];
    
    % Start with a grey screen 
    Screen('FillRect', wPtr, [0,255,0], FixCross(:,:,1)');
    vbl = Screen('Flip', wPtr);
    
    WaitSecs(1);

    
    vbl = Screen('Flip', wPtr);
    
     for i = 1:movieDurationFrames/2
            Screen('FillRect', wPtr,[255 255 0]); 
            vblBlack(i) = Screen('Flip', wPtr, vbl + (waitframes - 0.5) * ifi);
            Screen('FillRect', wPtr, [0 0 255]); 
            vblWhite(i) = Screen('Flip', wPtr, vbl + (waitframes - 0.5) * ifi);

     end
    
    WaitSecs(1);
    
end

Run PerceptualVBLSyncTest, be in awe, then compare against your code to find the obvious mistake. There’s many more problems with that code, but the reason for blueish should become clear.

-mario

1 Like

Hey! First of all thank you so much for your answer! It is true, the code was made quick and dirty and is not running like that. Thanks for the hint concerning PerceptualVBL. I tried on my system and I never seem to get a stable gray background … Probably it is a problem of hardware then? Could be so many possiblities now … However, I already switched to various monitos and PCs already and never seem to get a homogenous gray pattern.

Cheers

Hint: none of your specified colours are black or white to begin with… Black is [0 0 0], white is [255 255 255]

If PerceptualVBLSyncTest would not produce a gray on a fast display, that would be something new, given if flips between black and white. That your script produces blueish, given that it alternates between blue and yellow, is no surprise.