グレーティングの作成

function grating = GenerateGrating(wavelength, orientation, phase, imageSize)

% wavelength: pixel
% orientation: degree
% phase: degree
% imageSize: pixel


[x, y] = meshgrid(1:imageSize, 1:imageSize);
x = x-(imageSize+1)/2;
y = y-(imageSize+1)/2;

oriRad = -orientation/180*pi; % convert to radian
phaRad = phase*pi/180; % convert to radian
cpiRad = 2*pi/wavelength;

rotXY = (cos(oriRad).*x+sin(oriRad).*y); % rotate coordinates
grating = sin(rotXY*cpiRad+phaRad); % Sinusoidal grating: -1 to 1


関数は以上です。例えば、grating = GenerateGrating(40, 0, 90, 200); を実行すると、200 x 200 の配列変数 grating に波長 40 pixels で方位 0 度、位相 90 度のサイン関数の値が入ります。出力 grating の最小値は −1、最大値は 1 です。imshow(grating, [-1 1]); を実行すると、作成したグレーティングを画像で確認できます。

Psychtoolbox 関数は使用していませんが、imshow() を使うには image processing toolbox が必要です。imshow()を使えない場合は image(grating, ‘CDataMapping’, ‘scaled’); colormap(gray); axis image; で代用できます。

はじめよう実験心理学(2015, 勁草書房)』の第3章でもグレーティングの作成について解説していますが、そちらは初心者向けのシンプルな関数となっています。

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s