Memorandums

知覚・認知心理学の研究と教育をめぐる凡庸な日々の覚書

OctaveでPTB3を使う(Win)

2012-07-02 | PsychToolBox

 OctaveでPTB3を使う。
環境:Windows 7 Starter (Dell Latitude LAT2120, 32 bit)

1) Octave3.2.4 (32 bit版)をインストール(http://gnu-octave.softonic.jp/
2) Cドライブにtoolboxフォルダを作成(作らなくともよいが)
3) その下にPsychtooboxフォルダをコピー(Mac でインストールしていたもののフォルダから)
4) パスを通す(以下の指定フォルダ以下をすべて含める→addpath(genpath(' ') で指定)

>addpath(genpath('C:\toolbox\Psychtoolbox'))
>savepath

保存して終了。

5) ところが、

>Screen でエラーメッセージ。以下、それにしたがって,
>addpath('C:\toolbox\Psychtoolbox\PsychBasic\Octave3WindowsFiles\')
>savepath

6) さらに、>Screen
とすると今度は、
libARvideo.dll
がない?

そこで、
https://sites.google.com/site/ptbganba/test1/gui-qing-bao/octavenitsuite
を参考に、

C:\toolbox\Psychtoolbox\PsychContributed\ARToolkitStuff

にある4つのDLL(DSVL.dll、libARvideo.dll、msvcp71.dll、msvcr71.dll)をC:\Windows\system32にコピー。

7) しかしさらに
libgcc_tdm_dw2_1.dll
がないと言われた。そこで

C:\Octave\3.2.4_gcc-4.4.0\bin\libgcc_s_dw2-1.dll
をrename してC:\Windows\system32 へコピー。

cf. http://tech.groups.yahoo.com/group/psychtoolbox/message/10850

--------
以上で、やっと無事 MovieDemo が作動した。

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Block ごとにファイル名を変えてデータを保存

2011-11-20 | PsychToolBox

 

Block ごとにファイル名を変えてデータ(Data)を保存する。ファイル名の最後にblock番号を追加した。

 

subnum=input('Please enter your No.','s');% input Subject Number

 

blk=1;

blkn=5; % Number of blocks

while blk<blkn+1 %  ============= block

 

%re-order the 16 trials randomly

tr=1;

trn=16; % Number of trials

 

while tr<trn+1 % Start the trial -------------------------

 

% Stimuli Presentation

% Response 

tr=tr+1;

end;% End of one trial -----------------------

 

savefile=['Exp2011_',subnum,'_' num2str(blk)];

save (savefile,'Data'); 

blk=blk+1;

end; % End of one block =====================

 

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

画像の一部を提示する 2

2011-11-04 | PsychToolBox

読み込んだ画像の一部を選択し、画面上の位置を指定して提示する。

DrawTextureのパラメータで指定する。

1) 対角線上の2点で矩形領域を選択する。

2) 提示位置を指定する。同様に矩形領域で指定。指定した領域の大きさによって、拡大/縮小される。

%準備

screens=Screen('Screens');

screenNumber=max(screens);

[window,screenRect]=Screen(screenNumber,'OpenWindow',0,[],[],2);

[cx, cy]=RectCenter(screenRect); %画面の中心

%読み込みと変換

A=imread('sample.jpg');

w = Screen(window, 'MakeTexture', A);

%切り取り部分選択と提示位置指定(画面中央左側)

D=256;

Screen('DrawTexture', window, w, [1,1,D,D],[cx-2*D,cy-D/2,cx-D,cy+D/2]);

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

MakeTexture & DrawTexture

2011-10-30 | PsychToolBox

静止画像を提示する。

 

1) 画像sample.jpgを読み込む。

A=imread('sample.jpg');

 

2) memory に画像を保存(変換)。

w = Screen(window, 'MakeTexture', A);

 

3) 必要なときに、表示画面に提示。

Screen('DrawTexture', window, w);

 

 

cf.

http://psychtoolbox.org/PsychtoolboxTutorial

 



コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

64-bit版Windows 7でMatlab Psychtoolbox-3を使う

2011-08-25 | PsychToolBox

PTB3は、64bit Matlab (2010a, 2011a) では使えない。32bitでMatlabを使うには?

64-bit版Windows 7でMatlab Psychtoolbox-3を使う手順

 

2010a ならば:

Mac OS: If you installed Matlab R2010a with support for both 32-bit (maci) and 64-bit (maci64) architectures, you can launch Matlab in 32-bit mode from the command line using: '% matlab -maci'. You can also select the Matlab application icon, use command-I to open the Get Info dialog box, and select "Open in 32-bit mode".

cf. Psychtoolbox-3 - System Requirements

 

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Psychtoolboxをがんばる

2010-11-01 | PsychToolBox
Psychtoolboxをがんばる:心理学、実験、プログラミング
http://sites.google.com/site/ptbganba/
PTBのインストールから心理実験のサンプルまで(Windows)。
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PTB-3 & MATLAB Update

2009-11-06 | PsychToolBox
実験のためにMATLABとPsychtoolboxを更新。

http://psychtoolbox.org/wikka.php?wakka=PsychtoolboxDownload#remove-old


初心者向けのMATLABとPsychtoolboxについての講義が以下に掲載されている。実験プログラム例も豊富。
Class notes for beginners:
http://faculty.washington.edu/ionefine/MatlabCourseNotes07.html
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

screen 関数の基礎: 画面を消す

2007-11-22 | PsychToolBox
Flip を忘れずに
Screen('FillRect',window);
Screen(window,'Flip');


コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

ワイブル関数から閾値を求める関数

2007-11-19 | PsychToolBox
>>help Psychtoolbox

Psychometric - Psychometric function fitting.

FitWeibAlphTAFC - Fit Weibull with beta fixed, for TAFC (uses optimization toolbox).
FitWeibTAFC - Fit Weibull for TAFC experiments (uses optimization toolbox).
FitWeibYN - Fit Weibull for YN experiments (uses optimization toolbox).

FitWeibYN 解説

[alpha,beta,thresh50]=FitWeibYN(inputs,nYes,nNo,[alpha0],[beta0],[numFunCalls])

Fits a Weibull function to the passed yes-no data.

Requires the optimization toolbox.

INPUTS:
inputs Input levels
nYes Number of yes responses at
the corresponding input level
nNo Number of no responses at
the corresponding input level
alpha0 Initial guess for alpha (optional)
beta0 Initial guess for beta (optional)
OUTPUTS:
alpha
beta
thresh50 50% threshold

See also: FitWeibTAFC, FitFitWeibAlphTAFC, FitCumNormYN, FitLogitYN
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

screen 関数の基礎

2007-11-19 | PsychToolBox
>>help Psychtoolbox
から、
PsychBasic
さらに、
Screen
へ。

以下、基本的部分。
Screen is a MEX file for precise control of the video display. Screen has
many functions; type "Screen" for a list:
Screen


レファレンスの使い方
For explanation of any particular screen function, just add a question
mark "?". E.g. for 'OpenWindow', try either of these equivalent forms:
Screen('OpenWindow?')
Screen OpenWindow?

All the Screen Preference settings are documented together:
Screen Preference?


基礎事項
General Screen ARGUMENTS, common to most subfunctions of Screen:

"windowPtr" argument: Screen 'OpenWindow' and 'OpenOffscreenWindow' both
return a windowPtr, a number that designates the window you just
created. You can create many windows. To use a window, you pass its
windowPtr to the Screen function you want to apply to that window.

"rect" argument: "rect" is a 1x4 matrix containing the upper left and
lower right coordinates of an imaginary box containing all the pixels.
Thus a rect [0 0 1 1] contains just one pixel. All screen and window
coordinates follow Apple Macintosh conventions. (In Apple's the pixels
occupy the space between the coordinates.) Coordinates can be local to
the window (i.e. 0,0 origin is at upper left of window), or local to the
screen (origin at upper left of screen), or "global", which follows
Apple's convention of treating the entire desktop (all your screens) as
one big screen, with origin at the upper left of the main screen, which
has the menu bar. Historically we've had two different orderings of the
elements of rect, so, for general compatibility, all of the Psychophysics
Toolbox refers to the elements symbolically, through RectLeft, RectTop, etc.
Since 2/97, we use Apple's standard ordering: RectLeft=1, RectTop=2,
RectRight=3, RectBottom=4.


プログラムを止める
Stopping programs:

Command-zero brings the Matlab Command window forward. (Type a zero
"0" while holding the apple-cloverleaf "command" key down.)

Ctrl-C halts any program. (Type a "c" while holding down the "Ctrl"
key). Sometimes, Ctrl-C fails to halt progams executing in a Matlab process
run with the "-nojvm" option. To halt a runaway Psychtoolbox script in
Psychtoolbox you might resort to the Windows Task Manager to kill
the Matlab process. (Use Ctrl-Alt-Delete to open a window from which
you can start the Task Manager.)

OS-X:
Apple-Command-Escape executes "Force Quit" on Matlab, closing Matlab and all
of its windows.


刺激画面を消す
>> screen fillrect?

Usage:

Screen('FillRect', windowPtr [,color] [,rect] )

Fill "rect". "color" is the clut index (scalar or [r g b] triplet or [r g b a]
quadruple) that you want to poke into each pixel; default produces white with
the standard CLUT for this window's pixelSize. Default "rect" is entire window,
so you can use this function to clear the window. →画面を消す
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PTB-3: OS9 からの変更点 OpenWindow

2007-11-12 | PsychToolBox
MovieDemo から

'Openwindow'関連部分
L.119-127
% If there are multiple displays guess that one without the menu bar is the
% best choice. Dislay 0 has the menu bar.
screens=Screen('Screens');
screenNumber=max(screens);
以下、注意。
% Open a window. Note the new argument to OpenWindow with value 2,
% specifying the number of buffers to the onscreen window.
[window,windowRect]=Screen(screenNumber,'OpenWindow',0,[],[],2);


% Give the display a moment to recover from the change of display mode when
% opening a window. It takes some monitors and LCD scan converters a few seconds to resync.
WaitSecs(2);


cf.
OS9

Screen('Preference', 'VisualDebuglevel', 3);
pixelSize = 32; % You might change to 32 if 8 is not working, depending on OS9 or Windows.
[w, screenRect] = Screen(0,'OpenWindow',[],[],pixelSize); % Define your output screen as your monitor which is screen 0.
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

OS9からPTB-3へ

2007-11-05 | PsychToolBox
PTB-3 による刺激作成。OpenGLにまだ慣れない。

>>moviedemo

L.72
How do we draw ovals during an animation if we can not store them
within offscren or textures? Unlike QuickDraw, OpenGL is fast enought
to render all drawing commands directly to the display during an
animation loop. Except for MATLAB matrices stored in textures, there
should be no need to prerender and buffer what is displayed during
animation.

要は単に「描け」ということか。
% PTB-3:
%
% %generate textures here...
% for i=1:numberOfMovieFrames
% Screen('DrawTexture', texture(i), window);
% Screen(window, 'Flip');
% end
%

Screen 命令の基本
>> Screen
Usage:

% Activate compatibility mode: Try to behave like the old MacOS-9 Psychtoolbox:
oldEnableFlag=Screen('Preference', 'EmulateOldPTB', [enableFlag]);

% Open or close a window or texture:
[windowPtr,rect]=Screen('OpenWindow',windowPtrOrScreenNumber [,color] [,rect] [,pixelSize] [,numberOfBuffers] [,stereomode] [,multisample][,imagingmode]);
[windowPtr,rect]=Screen('OpenOffscreenWindow',windowPtrOrScreenNumber [,color] [,rect] [,pixelSize]);
textureIndex=Screen('MakeTexture', WindowIndex, imageMatrix [, optimizeForDrawAngle=0] [, specialFlags=0] [, floatprecision=0] [, textureOrientation=0] [, textureShader=0]);
Screen('Close', windowOrTextureIndex);
Screen('CloseAll');

% Draw lines and solids like QuickDraw and DirectX (OS 9 and Windows):
Screen('SelectStereoDrawBuffer', windowPtr, bufferid);
Screen('DrawLine', windowPtr [,color], fromH, fromV, toH, toV [,penWidth]);
Screen('DrawArc',windowPtr,[color],[rect],startAngle,arcAngle)
Screen('FrameArc',windowPtr,[color],[rect],startAngle,arcAngle[,penWidth] [,penHeight] [,penMode])
Screen('FillArc',windowPtr,[color],[rect],startAngle,arcAngle)
Screen('FillRect', windowPtr [,color] [,rect] );
Screen('FrameRect', windowPtr [,color] [,rect] [,penWidth]);
Screen('FillOval', windowPtr [,color] [,rect]);
Screen('FrameOval', windowPtr [,color] [,rect] [,penWidth] [,penHeight] [,penMode]);
Screen('FillPoly', windowPtr [,color], pointList);

ひとまずこのぐらいで十分。
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PTB-3: OS9 からの変更点

2007-07-24 | PsychToolBox
>> edit moviedemo
:
The comments below review the difference between the OS 9 version of
the toolbox and PTB-3.

New and different on OS Psychtoolbox:

The OS 9 Psychtoolbox is based on QuickTime and PTB-3 is
based on OpenGL. Differences between these underlying graphics libraries
have unavoidably resulted in differences between the OS 9 and PTB-3
versions of Screen; Some subfunctions of OS 9 Screen are replaced by
similar, but not identical functions in PTB-3.

In OS 9: /// In PTB-3

WaitBlanking /// Flip
PutImage /// MakeTexture
CopyWindow /// DrawTexture

PTB-3 は使いやすくなった(MATLAB R2007aは、というべきか)のだが、OS 9 版からのプログラムの修正がやや面倒だ。以下のサンプルを参考にすればわかりやすい。それでも少し時間が必要と思われる。
cf.
MovieDemo.m

Animation loops: OS 9 VS PTB-3

To understand the differences between OS 9 and PTB-3 Screen its helpful
to compare animation loops:

OS 9:

%create and fill offscreen windows here...
for i=1:numberOfMovieFrames
Screen(window, 'WaitBlanking');
Screen('CopyWindow', offscreenWindow(i), window);
end

PTB-3:

%generate textures here...
for i=1:numberOfMovieFrames
Screen('DrawTexture', texture(i), window);
Screen(window, 'Flip');
end
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Rushと画面のちらつき

2007-04-09 | PsychToolBox
>>help Rush

Screen('Screens'); % Make sure all functions (Screen.mex) are in memory.
i=0; % Allocate all variables.

ここまではおまじない。
以下、loop内は;を忘れずに。

loop={
'for i=1:100;'
'Screen(window,''WaitBlanking'');'
'Screen(''CopyWindow'',w(i),window);'
'end;'
};
priorityLevel=MaxPriority(window,'WaitBlanking');
Rush(loop,priorityLevel);

自作のプログラムでちらつきが残るのはOSX10.3.9のためか。

cf.
MovieDemo.m サンプルはやや不親切。>>help Rush 内の例を(そのまま)参考にするほうが早い。
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Screen, SetDrawingRegion:Psychtoolbox/Matlab

2006-11-20 | PsychToolBox
>>screen SetDrawingRegion?

Usage:

Screen(windowPtr,'SetDrawingRegion',shapeSpec,[shapeFlag])

Make subsequent drawing to the window visible only if it is within the specified
region.
Call with rect equal to screenRect to reestablish the entire screen. Drawing
outside the region is suppressed, but still takes the normal amount of time to
complete.

If shapeFlag == 0 [default], shapeSpec is a rect, region is rectangular.
If shapeFlag == 1, shapeSpec is a rect, region is oval.
If shapeFlag == 2, shapeSpec is a point list, region is polygonal.
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする