How could I calculate the size of dots, height, and width of cylinder by pixel?

5 ビュー (過去 30 日間)
희영
희영 2024 年 1 月 5 日
コメント済み: Angelo Yeo 2024 年 1 月 11 日
Hello.
I am a beginner in matlab.
I got the code in psychtoolbox that can make rotating cylinder.
I remember getting help here last time, so I'm asking a new question about the problem I wasn't able to solve.
I should know the width and height of cylinder and dot size by pixel unit to calculate visual angle.
But I could not know what matlab code to do this, only found the matlab code that change vector to pixel or image to pixel.
So I want to calculate the width and height of below cylinder code and dot size by pixel unit.
If anyone knows anything about this, I would appreciate it if you could let me know.
Thank you for reading this.
Below is rotating cylinder code file. It is consist of two file.
# first code file
clear;
makeCyl = 1;
%% parameters
W = 153; %width
ndot = 900;
NumFrames = 86;
stepD = 400; % ie the half perimeter of the cylinder
cylR = stepD/pi; %guarantee the cylinder aprroaches with the same distance per 180 degree as the figure walks a step
%% cylinder
if makeCyl
backCol=0.9;
dotx = sin((rand(1,ndot)-0.5)*pi)* W/2; %dots are more concentrated on the two boundaries after ttransformed to sin, more natural than sqrt
dotc = ones(1, ndot);
angs = 2*pi* rand(1,ndot);
angpf = 2*pi/NumFrames; %angle per frame
Cylin = NaN(NumFrames*3,ndot); %keep it the same format as the mov file
dotC = cell(NumFrames,1);
for zz = 1:NumFrames
Cylin(zz*3-2,:) = dotx;
Cylin(zz*3-1,:) = cylR*cos(angs);
Cylin(zz*3,:) = cylR*sin(angs); % all dots are in the same depth so that it won'd contain perspective cue when drawn by moglDrawDots3D
angs = angs-angpf;
dotc = ones(1, ndot);
dotc(:, mod(angs,2*pi)<=pi) = backCol;
dotC{zz}= [1;1;1]*dotc;
end
save('Cylin_aaa','Cylin' ,'ndot');
end
# second code file
InitializeMatlabOpenGL;
load('Cylin_aaa.mat')
nFrames = 60;
fr = 1;
InitializeMatlabOpenGL; % open GL reset, moglDrawDots3D Required for function execution
%Screen('Preference', 'SkipSyncTests', 1);
Screen('Preference', 'SkipSyncTests', 1) % Skip sync test for testing
whichScreen = max(Screen('Screens'));
[w, screenRect] = Screen('OpenWindow', whichScreen,[0 0 0],[]); % small screen output
ScreenCenter = [screenRect(3)/2 screenRect(4)/2];
commandwindow;
while fr <= 86
thefr = fr;
while thefr > nFrames; thefr =thefr-nFrames; end
disp(thefr); % Check frame progress
this_xyz = Cylin(thefr*3-2:thefr*3,:);
Screen('DrawDots',w, this_xyz(1:2,:),[],[255 255 255],ScreenCenter, 0);
% moglDrawDots3D(w, this_xyz, 1, [1 1 1]); %
Screen('Flip',w);
%WaitSecs(0.05); % To see the dot move slowly
fr = fr +1;
end
sca;

採用された回答

Angelo Yeo
Angelo Yeo 2024 年 1 月 9 日
編集済み: Angelo Yeo 2024 年 1 月 9 日
1. By default, each dot has a size of 1 pixel. See Psychtoolbox-3 - Screen(‘DrawDots’) for details. To quote:
“size” is the diameter of each dot in pixels (default is 1)
2. In Psychtoolbox, drawing unit of dots is pixels. For example, the script below will plot 2 dots at center and 10 pixels right to the center.
InitializeMatlabOpenGL; % open GL reset, moglDrawDots3D Required for function execution
Screen('Preference', 'SkipSyncTests', 1) % Skip sync test for testing
whichScreen = max(Screen('Screens'));
[w, screenRect] = Screen('OpenWindow', whichScreen,[0 0 0],[]); % small screen output
ScreenCenter = [screenRect(3)/2 screenRect(4)/2];
commandwindow;
myDots = ...
[0, 10;
0, 0];
Screen('DrawDots',w, myDots,5,[255 255 255],ScreenCenter, 0);
Screen('Flip', w);
KbStrokeWait
sca;
3. According to #2, the width and height of the cylinder can be calculated in pixel like below.
load('Cylin_aaa.mat');
temp = Cylin(1:2,:); x = temp(1,:); y = temp(2, :);
width = max(x) - min(x) % pixels
width = 152.9998
height = max(y) - min(y) % pixels
height = 254.6442
  2 件のコメント
희영
희영 2024 年 1 月 11 日
Your answer is exactly what I wanted to find!
Thank you for helping me.
For you help, I can make the stimuli for my experiment!
Have a good day :)
Angelo Yeo
Angelo Yeo 2024 年 1 月 11 日
Thanks for the feedback. I am glad it helped 😊.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by