How to convert spatial frequency from 1/pixels to cycles per degree of visual angle?

31 次查看(过去 30 天)
Hello everybody, my research field is visual neuroscience and I need to develop and experiment using sine-wave gratings. I found a code that works in Psychtoolbox to generate the gratings. It is good enough for what I need but I would like to use cycle per degree of visual angle instead of spatial frequency in 1/pixels. I know that I would need to provide the screen information as distance, height and maybe resolution, but I don't know how to do it, do you?
the code is
%%%Program SinewaveGrating.m
c = 0.25; % contrast of the grating
f = 1/32; % spatial frequency in 1/pixels
t = 0*pi/180; % tilt of 0 degrees into radians
s = 50; % size of the grating
% window of the Grating
[x, y] = meshgrid(-128:127, 128:-1:-127);
M1 = uint8(127*(1 + c*sin(2.0*pi*f*(y*sin(t) + x*cos(t)))));
% uint8 converts the elements of the array into unsigned
% 8-bit integers. Values outside this range are mapped
% to 0 or 255.
showImage(M1, 'grayscale' );

回答(2 个)

David Goodmanson
David Goodmanson 2018-1-10
Hello Caroline,
Although it's unrealistic, suppose for the moment that the spacial frequency is 1 cyc/pixel. For pixels of width w, with the eye at distance d from the screen, the subtended angle is 1 pixel = w/d radians. Substituting in then, 1 cyc/pixel = (d/w) cyc/radian, and in terms of milliradians,
1 cyc/pixel = (d/w)*1e-3 cyc/milliradian.
If the screen has width L, and there are N pixels across the width (commonly called resolution), then
1 cyc/pixel = (d/L)*(N*1e-3) cyc/milliradian.
So to be clear, if there are q cycles per pixel, then [q*(d/w)*1e-3] or [q*(d/L)*(N*1e-3)] is a numerical value, and there are that many cycles per milliradian.
Same for screen height and number of pixels in that direction.
Displays are made to approximate the angular resolution of the eye; there is obviously no point in making them much better than that. cyc/pixel can be on the order of 1, and for the eye I believe resolution is on the order of 1 in cyc/milliradian. Since d/L and N*1e-3 are on the order of 1, the last equation looks reasonable.
Now for the tricky part. Many displays have separate r,g,pixels. Some of the newer displays may have all three colors emitted by one pixel. Pixels may or may not have the same dimension in width as in height. So you have to establish what is going on for a given display. Screen dimension and 'resolution' (3840 × 2160 or whatever the number) are a good part of the story, but not all. Just for interest I used a magnifying glass to look at the monitor I am using right now to see what the pixels illuminating this text look like. (It takes about 6 of them to create the serif on the bottom of an 'i' in the text window for creating an answer, not in the window you see that displays it. But each of those is three separate rgb vertical stripes side by side.)
w/d = radians is straight physics, but I encourage you to go to wikipedia and a bunch of other web sites to verify all of this. Don't take my word for it since visual neuroscience is not something I know much about. And even if it were, you should not take my word for it anyway.

Anil Yadav
Anil Yadav 2022-11-4
%%%Program SinewaveGrating.m
c = 0.25; % contrast of the grating
f = 1/32; % spatial frequency in 1/pixels
t = 0*pi/180; % tilt of 0 degrees into radians
s = 50; % size of the grating
% window of the Grating
[x, y] = meshgrid(-128:127, 128:-1:-127);
M1 = uint8(127*(1 + c*sin(2.0*pi*f*(y*sin(t) + x*cos(t)))));
% uint8 converts the elements of the array into unsigned
% 8-bit integers. Values outside this range are mapped
% to 0 or 255.
showImage(M1, 'grayscale' )

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by