Calculating visual angles in eye movement data
Oct 5
4 min read
Overview
In eye tracking, eye movement data is generally described in terms of visual angles rather than pixels or millimeters. Visual angles, as Tobii highlights in their white paper, allows us to describe eye movements, such as how fast our eyes move from one location to another, while accounting for the environment in which the data was collected (e.g. size of computer screen, distance from computer screen, etc). As a result, many eye movement measures, such as an eye tracker's accuracy and precision, are commonly described in terms of visual angles.
However, eye trackers and commonly used eye tracking software, such as the Tobii Pro SDK, often provide eye movement data in millimeters or normalized coordinates. It is then left to the user to calculate the visual angles from the collected eye movement data.
As a result, in this tutorial, we'll go over the simplest way to calculate visual angles from eye movement data. Afterwards, we'll highlight some caveats regarding this approach presented by other researchers, pointing you to their work for additional information.
Simple visual angle calculation
Transforming gaze positions from normalized values to millimeters
For this tutorial, I collected my own eye movement data using the Tobii Pro SDK, which provides gaze positions on the computer screen in 2D normalized coordinates (x,y) via its Active Display Coordinate System (ADCS). I also collected the timestamp at which each data point was collected in seconds. A sample of the data, which might be very similar to one that you might have, is below.
Timestamp (s) | Gaze X (norm) | Gaze Y (norm) |
0.000 | 0.504 | 0.473 |
0.016 | 0.506 | 0.474 |
0.034 | 0.506 | 0.477 |
.... | .... | .... |
The first step when working with this type of eye movement data is to convert the normalized values into millimeters (mm). To do so, make sure that you write down the following information regarding the geometric set-up where the eye movement data was collected. Note that you can measure this information using a ruler or a tape measure.
Width and height of the computer display (in mm)
Distance of the person from the computer display (in mm)
In my case, which you can see in the image below, the width and height of the computer display was 525 mm x 295 mm, respectively. My distance from the computer display was approximately 520 mm. We can then convert any gaze point recorded by the eye tracker in normalized coordinates, such as (0.5, 0.5) (orange dot), into millimeters by multiplying each value by its corresponding width or height, creating the point (262.5, 147.5).
Note that, in the Tobii Pro SDK's ADCS, the origin point (0,0) occurs at the top left of the computer display, as depicted by the green and red arrows on the image.
In Python (3.9.6), a quick way to carry out these transformations is via the following code:
At the end of this code, the data will have two additional columns with gaze values represented in millimeters.
Timestamp (s) | Gaze X (norm) | Gaze Y (norm) | Gaze X (mm) | Gaze Y (mm) |
0.000 | 0.504 | 0.473 | 264.947 | 139.639 |
0.016 | 0.506 | 0.474 | 265.850 | 140.094 |
0.034 | 0.506 | 0.477 | 265.795 | 140.900 |
.... | .... | .... | ... | ... |
Calculating visual angle between gaze data
The simple way to calculate the visual angle between two gaze points is to use trigonometry, as described by Duchowski et al. Consider the following two points on the computer display:
In this case, we have a green gaze point and a blue gaze point. Drawing a straight line D (i.e. the distance from the computer screen) allow us to calculate the angle theta using the following equation, where r represents the Euclidean distance between the two gaze points.
For instance, assume that the green point is located at (203.67, 76.86), while the blue point is located at (169.35, 142.51). The Euclidean distance between the two points (i.e, r) is approximately 74.08 mm, while as mentioned previously, D is about 520 mm.
Plugging these values into the equation, we get that the visual angle theta is approximately 8.14 degrees.
However, doing this process manually for all our eye movement data collected would take forever! Just for my own data collected for approximately 37 seconds, I'd have to repeat this calculation 2249 times.
We can carry out this calculation in Python pretty quickly by iterating over our data. Note that the following code was primarily written to showcase the steps needed to calculate the visual angles, and could easily be re-written to be more efficient.
First, let's create a new dataframe that contains the two gaze points that we need to calculate the visual angle. To do so, we can create a new dataframe with each row shifted by one using Pandas' .shift method, which we can then combine with the original data using Panda's .concat method.
Afterwards, let's define functions that represent the calculations that we need to apply at each row. The code will primarily use Pandas' .apply method to iterate over each row in the dataframe and apply each of these function.
Now that we have everything we need, we can just apply the functions to the dataframe, starting first by calculating the distances followed by calculating the visual angl
And that's it! Our dataframe will now include both the distance between gazes and the visual angle between gazes. We did it!
Important information to know
Following this approach relies on the assumption that our distance from the computer screen is perpendicular to the computer display, which, as Duchowski et al. points out, generally does not hold. For instance, when eye movements occurr far away from the center of the screen. As a result, Duchowski et al. explains, the visual angle calculation needs to be corrected, which they discuss in their paper.
In addition, as Tobii points out in their white paper, newer eye trackers provide additional information regarding the position of the eyes, the eye tracker, as well as the computer screen in 3D. Such information was not previously available, and as a result, the assumption that the distance from the computer screen being perpendicular was needed. As a result, the visual angle between gaze points can be calculated with more accuracy with other approaches, as the distance between the eyes and the computer screen can be calculated.
I encourage you to check out those papers! There might be other important caveats to consider, but these papers will serve as a great starting point!