On Converting Pixels to Degrees

The Warping Effect

In our mantis contrast sensitivity paper (http://tinyurl.com/mantiscsf) we used the following formula to calculate the spatial frequency of grating stimuli in cycles per degree (cpd):

eqn

Where ppx is the grating period in pixels, sr is the screen resolution in px/cm and viewD is the viewing distance in cm.

This equation assumes a linear correspondence between screen pixels and the visual angle subtended by these pixels (in degrees). The conversion ratio is effectively the average over one grating period; for example a spatial period of 100px corresponds to 20.25 degs making the effective conversion ratio 4.94 px/deg.

When viewD is sufficiently large (which is typical for human experiments) the assumption of a linear correspondence between screen pixels and angle subtended holds (i.e. differences are negligible). However, for small viewD there could be considerable differences as gratings subtend smaller angles the further they are from the centre and thus the stimulus appears to be “squeezed” near the screen ends.

The plots below demonstrate this effect. The top two plots show a horizontal sinusoidal grating of period 5 px (sr = 40 px/cm) as perceived by an observer 7cm away from the monitor. Instead of a constant frequency in cpd there is actually a range of frequencies going from low (at the screen centre) to high (at both ends). The bottom plot is a frequency spectrum showing how broadband this actually is. Using the equation above fs = 0.978 cpd for this stimulus while the actual spectrum goes from 0.08 all the way up 0.6 cpd.

spec1

How to correct for this

One way to correct for this is to incrementally increase the grating period as we move away from the screen centre. For an observer standing sufficiently away from the monitor such a stimulus would appear squeezed at the centre and stretched at the sides. At the right viewing distance, however, all gratings will subtend the same visual angle.

This can be done in multiple ways in Matlab. I’ve found the following particularly intuitive and easy to implement:

  1. Calculate the visual degree corresponding to each px on the screen given a viewing distance and a screen resolution (the function px2deg does this for you)
  2. Use the obtained degrees array to calculate grating/stimuli luminance level

For example, to render a sinusoidal grating of frequency 0.1 cpd on a monitor that is 1920px wide I do:

scrWidthPx = 1920; % px
screenReso = 40; % px/cm
viewD = 7; % cm
freq = 0.1; % cpd
degs = px2deg(scrWidthPx, screenReso, viewD);
y = cos(2*pi*degs*freq);

The array y now contains 1920 luminance levels which, when rendered horizontally across the 1920 screen pixels, would simulate a grating of 0.1 cpd at the specified viewing distance. The plots below demonstrate how this is perceived by the observer.

spec2

The rendered stimulus is now narrow-band as intended.

 Precautions

The correction above assumes a certain viewing distance and that the observer is positioned laterally in front of the screen centre. If the observer position changes then the perceived stimulus will have a different spectrum and so it is important to ensure that subjects (in our experiments, mantids) are placed at the correct viewing distance both away from the screen and laterally to minimize any errors.

How does this affect our CSF Data

The “warping effect” that we described above must be taken into consideration when interpreting the data we published in the mantis CSF paper. Each spatial frequency we rendered was actually perceived by the mantis as a broadband signal and so the actual mantis CSF is likely more narrow-band compared to what we reported.

Bizzare Issue with LCD Monitors

This is about an unusual flickering artefact with LCD monitors that I noticed while working on a visual stimulus. I am posting about this for reference and to share information about what can potentially have a big impact on psychophysics/electrophysiology experiments that use LCDs to render visual stimuli.

The effect can be induced by launching a PTB window and flashing it (painting min/max luminance at alternate cycles) for 30+ seconds. After closing the window, persistent flashing is observed in dark areas across the screen. What really struck me as weird is that this happens *after* closing the PTB window and would not go away after closing Matlab, shutting down the machine or even unplugging the DVI connector (in the latter case you can see the flickering on top of the “monitor idle” box that floats around when the monitor is disconnected). These observations rule out any software/driver/OS issues as the source of this issue and leave only the monitor itself.

Luckily one of the folks on PTB forums seems to know what’s causing this:

It’s the timing and content of your stimulus interfering with the panels LCD inverter cycle, causing a buildup in the liquid crystal, as they only like AC driving voltage over longer periods of time. A known problem in many (most?) LCD panels, due to the way the physics of liquid crystal displays works. Periodic strong contrast changes at video refresh rate like your stim and some other high frequency spatial patterns are especially effective at triggering it.

LCD’s – more ways to screw up your low level stimuli properties than your wildest dreams could imagine.
-mario

Thread : https://groups.yahoo.com/neo/groups/psychtoolbox/conversations/topics/18208

The flickering goes away gradually over the course of ~10 minutes (on Dell U2412M) so there’s no permanent hardware damage, just another LCD quirk that you need to be aware when designing any visual stimuli involving persistent flashing!

This is a minimal Matlab script to reproduce this effect:

function testFlickerAfterEffect
duration = 30; % seconds
%% open PTB window
SCREEN_ID = 1;
m = Screen(‘Windows’);
if (~isempty(m))

% exit if any PTB windows are already open

return;

end
PsychImaging(‘PrepareConfiguration’);
PsychImaging(‘AddTask’, ‘FinalFormatting’, ‘DisplayColorCorrection’, ‘SimpleGamma’);
PsychImaging(‘OpenWindow’, SCREEN_ID, 0.5, [], [], [], 0, 0);
m = Screen(‘Windows’);
window = m(1);
%% render
col = 0;
h = tic;
while toc(h) < duration

col = 1 – col; % toggle

Screen(window, ‘FillRect’ , [1 1 1] * col * 255, []);

Screen(‘Flip’, window);

end
Screen(‘CloseAll’);
end

Mantis under Infrared

This week we acquired an infrared camera and realized that mantids glow like light bulbs under infrared!

Below are two shots for a mantis using a conventional (left) and our new infrared (right) cameras.

Apart from producing very cool mantis photography, this camera has the added advantage of providing a clear outline of the subject mantis in each trial. This is very useful as a first step towards building video processing algorithms which we intend to use as a replacement for human observers in mantis experiments.

Camouflage and Mimicry Workshop

Camouflage and Mimicry Workshop

Our lab has taken part in organizing the Camouflage and Mimicry workshop at the British Science Festival 2013 in Newcastle. Lab members Lisa, Paul, Sid and I (although to a much lesser extent) have participated in setting up a number of activities to introduce visiting young students to some of the fascinating visual trickery that living organisms employ to survive.

The workshop activities included a range of captivating presentations, engaging posters, live insect displays, visual illusions and even an actual scientific experiment. Our lovely visitors showed great interest and demonstrated their breadth of knowledge by giving surprising good answers to some of the presenters’ questions.

Below are some photos from the event.

(Above) Paul and Sid showing students that “things are not always what they seem to be”. On both sides of the natural competition between prey and predators; butterflies pose as poisonous species to deter predators and predators use 3D vision to detect an otherwise invisible prey.

(Above) Corry Gellatly giving students a taste of real science by asking them to “predate” (pick) non-poisonous spiders. Students begin by picking random spiders but later realize that some visual clues can help them in their task. Corry reveals the secret at the end of the experiment and of course … hands the top scoring student a “predator of the day” prize!

The live insect display gathered a lot of attention; student were fascinated by stick insects, praying mantids, assassin bugs and hissing cockroachs!

We’re all looking forward to future public engagement events. We hope the workshop has introduced our work and some of the questions we’re attempting to answer to the highly inquisitive minds of the future!