PTB Screen('DrawTexture') does not draw the image with the defined size

2 Ansichten (letzte 30 Tage)
Cemre Topcu
Cemre Topcu am 30 Dez. 2020
Bearbeitet: Cemre Topcu am 12 Jan. 2021
Hi everyone! I am computerizing a behavioral assessment by using PsychToolBox (ptb). I show my questionnaire with ptb because it will be just a part of experiment in which we use VPixx as second monitor. I cannot simply put a figure window on the experimental monitor. In the questionnaire, participants will report a frequency by clicking on the value on a scale that I print on the screen and then pressing return key to submit their response.
My problem is that the calculated result (data) is lower than the clicked value. It is not due to a calculation mistake, I think. I noticed that the script draws the scale (the image 'ruler.jpg') smaller than I defined with c_rect variable. Does anyone have an idea about this? Any help will be appreciated.
The script as simplified is the following, and it should work by itself without any dependencies:
[Edit: I found my answer. Probably, it is related to the retina screen. I have the problem with my MacBook Pro 13-inch (2017) but not in my office PC.]
PsychImaging('PrepareConfiguration');
ptb.scrn.n = max(Screen('Screens'));
ptb.w.bg = (WhiteIndex(ptb.scrn.n) + BlackIndex(ptb.scrn.n)) / 2;
[ptb.w.id, ptb.w.rect] = PsychImaging('OpenWindow', ptb.scrn.n, [ptb.w.bg]);
Screen('BlendFunction', ptb.w.id, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% First flip
Screen('Flip', ptb.w.id);
KbQueueCreate(); % for subject's responses
KbQueueStart();
% The scale to draw on screen for the report of frequency and speed
rulerFile = 'ruler.jpg'; % filename
matrix_im = imread(rulerFile); % read image
matrix_im = imresize(matrix_im, [100,850]); % resize image
shapeScale = Screen('MakeTexture', ptb.w.id, matrix_im); % create texture
c_x = RectWidth(ptb.w.rect)/2; % center x of rectangle
c_y = RectHeight(ptb.w.rect)/2 + ptb.w.rect(3)/5; % center y of rectangle
c_rect = [0 0 850 100]; % rectangle for scale
c_rect = CenterRectOnPoint(c_rect, c_x, c_y); % shift the rectangle at lower part of screen
a = (c_rect(3)-c_rect(1))/34; % share for visualization
ruler_length = [c_rect(1)+a, c_rect(3)-a]; % borders of scale
textOnScr = 'Click to report your perception. Press return to submit your response.';
m = 1;
p = 0;
w_text = '';
while m % until return-key is pressed to save the response
DrawFormattedText(ptb.w.id, textOnScr, 'center', 'center', [1 0 0]);
Screen('DrawTexture', ptb.w.id, shapeScale, [], c_rect);
Screen('Flip', ptb.w.id);
[x, y, ~] = GetMouse(ptb.w.id); % check mouse-click
[~, key] = KbQueueCheck(); % check keys
if key(KbName('escape')); break; end % if escape, quit
% ------------------------------------------------------------------- %
% ------------------------- check key press ------------------------- %
if ismember(find(key), KbName('return')) % if return, save the response and finish this question
m = 0;
end
if key(KbName('escape')); break; end % if escape, quit
% ------------------------- check key press ------------------------- %
% ------------------------------------------------------------------- %
end % end of question
% calculate the response
data = ((x - ruler_length(1))/(ruler_length(2) - ruler_length(1)))*100;
% close
WaitSecs(0.5);
PsychHID('KbQueueStop')
PsychHID('KbQueueRelease')
Screen('CloseAll')
close all

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by