TransformingVisualAngleAndPixelSize - MRC CBU Imaging Wiki
location: TransformingVisualAngleAndPixelSize

Transforms between visual angle (deg) and stimulus size (pixels)

If you are testing both in and outside the scanner, it is often useful to standardise the size of your stimuli in terms of degrees visual angle. The screen in the scanner is surprisingly small and far away, so stimuli often need to be made considerably larger than you might think to match the percept you get from e.g. testing on the mimic.

There are two Matlab functions available for transforming visual angle to stimulus size, and transforming stimulus size to visual angle. You can download the attached functions, or copy the code below.

OUTDATED DEFAULTS Please note, this code was last updated in 2009. The algorithm works, but the default values are no longer valid. Please consult CbuStimulusDelivery to obtain current parameters (which will be different for the LCD, goggles and projector systems).

Visual angle to stimulus size

% Provides x,y size in pixels to produce a given size in visual angle. 
% If the screen and distance parameters are undefined, we use the CBU
% scanner settings (see 
% http://imaging.mrc-cbu.cam.ac.uk/mri/CbuStimulusDelivery). If using default
% CBU scanner parameters, the sizey input is also optional.
% use: [sizex,sizey] = visangle2stimsize(visanglex,[visangley],[totdistmm],[screenwidthmm],[screenres])
% 25/9/2009 J Carlin

function [sizex,sizey] = visangle2stimsize(visanglex,visangley,totdist,screenwidth,screenres)

if nargin < 3
        % mm
        distscreenmirror=823;
        distmirroreyes=90;
        totdist=distscreenmirror+distmirroreyes;
        screenwidth=268;

        % pixels
        screenres=1024;
end

visang_rad = 2 * atan(screenwidth/2/totdist);
visang_deg = visang_rad * (180/pi);

pix_pervisang = screenres / visang_deg;

sizex = round(visanglex * pix_pervisang);

if nargin > 1
        sizey = round(visangley * pix_pervisang);
end

Stimulus size to visual angle

% Quick convenience function to convert stimulus size in pixels to degrees
% visual angle. If the screen and distance parameters are undefined, we use
% the CBU scanner settings (see 
% http://imaging.mrc-cbu.cam.ac.uk/mri/CbuStimulusDelivery). If using default
% CBU scanner parameters, the sizey input is also optional.
% use: [visanglex,visangley] = stimsize2visangle(sizex,[sizey],[totdistmm],[screenwidthmm],[screenres])
% 25/9/2009 J Carlin

function [visanglex,visangley] = stimsize2visangle(sizex,sizey,totdist,screenwidth,screenres)

if nargin < 3
        % mm
        distscreenmirror=823;
        distmirroreyes=90;
        totdist=distscreenmirror+distmirroreyes;
        screenwidth=268;

        % pixels
        screenres=1024;
end

visang_rad = 2 * atan(screenwidth/2/totdist);
visang_deg = visang_rad * (180/pi);

visang_perpix = visang_deg / screenres;

visanglex = sizex * visang_perpix;

if nargin > 1
        visangley = sizey * visang_perpix;
end

CbuImaging: TransformingVisualAngleAndPixelSize (last edited 2021-04-19 13:12:09 by JohanCarlin)