> For the complete documentation index, see [llms.txt](https://help.imotions.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.imotions.com/lab/analysis/biosensor-analysis/r-notebooks-perclos-percentage-of-eye-closure.md).

# R notebooks: PERCLOS (PERcentage of eye CLOSure)

Run the PERCLOS R notebook to measure the percentage of eye closure, a drowsiness metric, from eye trackers that provide eyelid data, relative to a baseline.

*The PERCLOS R notebook computes the PERcentage of eye CLOSure from eye trackers providing eyelid data (available in iMotions v11.1.2 or newer).*

## PERCLOS Overview

Drowsiness is commonly studied in Human Factors research and other application areas. One way to measure drowsiness is through eyelid opening. PERCLOS, the abbreviation for PERcentage of eye CLOSure, is a metric often cited in the literature (for an overview, refer to [this publication by Abe, 2023](https://academic.oup.com/sleepadvances/article/4/1/zpad006/7000589)). Rather than blinks, it reflects slow eyelid droops and hence is used as an indicator of fatigue. For this, the baseline level of eyelid opening is established. Then, a threshold for eye closure is set (typically, 80%). iMotions calculates statistics on the amount of eye closure, and provides moment-to-moment visualizations of eye closure over time.

#### Requirements

* iMotions v11.1.2 or newer
* Study containing data from Neon by Pupil Labs, Smart Eye Pro, or Smart Eye Aurora

## How to process PERCLOS

1. Select a study that contains eye data.
2. Create a new analysis for the study (with the Add Analysis button that appears when hovering on the study).
3. Advance through the steps “Segmentation Settings” and “Segmentation Criteria”.
4. In “Signal processing”, click “+” next to “Active flows”.
5. For “Devices”, select your eye tracker.
6. For “Algorithm”, select “Eyetracker PERCLOS”
7. Confirm or adjust settings (described below).
8. Click Next to proceed to Select Stimuli and initiate processing

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-7c768eb83ef5bb211bfe52242d2ddedbc0902af8%2F7e434fcb5d_image-CO0N0VUG.webp?alt=media)

### Algorithm Settings

#### Baseline Setting

Choose how you want to establish a **baseline** for normal eyelid opening with the **Entire recording** or an **Annotation**.

We recommend that you annotate a short (5 seconds) time interval for every respondent when they are just neutrally looking straight ahead with their eyes in their natural opening position. Use the same Annotation name across respondents and insert the name of the Annotation in the dedicated field under *Signal processing*.

Please note: This Annotation needs to be set for all respondents before running the PERCLOS notebook.

Alternatively, iMotions can establish a baseline based on the entire recording. However, since artifacts are expected, we recommend to utilize Annotations for the baseline.

#### Threshold Settings

The notebook calculates the maximum eye opening value during the selected period, and uses this as eye opening baseline during subsequent processing steps.

The option for Momentary PERCLOS is optional. With this parameter toggled on, you receive an additional graph in the Replay showing you the PERCLOS metric over time. This option also allows you to receive an additional moment-to-moment csv export.

The Moving window length (default 10 sec) determines the time interval considered to calculate the current percentage of time with eyes closed. As an example: If eyes were classified as closed (based on the set threshold) during 5 seconds over the past 10 seconds, PERCLOS at the current time stamp is 50%.

Window increment step sets the step size at which the moving window is updated. Smaller increment steps will give a smoother graph for momentary PERCLOS.

## Method

**Data retrieval:** Eyelid aperture signals (left/ right) are retrieved from the selected eyetracker.

**Baseline estimation (100% openness):** A baseline representing fully open eyes is computed per respondent:

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-a3a210195f3be8946cd9aa0d040adefc1bc62882%2F01edd5feaa_image-PVJAURGP.webp?alt=media)

where

* BaselineL and BaselineR are the per-eye open-eye baselines representing 100% openness
* ApertureL and ApertureR are the eyelid aperture signals

**Eye closure percentage:** At each time t, the eye closure percentage is the mean of the left and right eyes’ closure relative to their open-eye baselines:

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-ca6261cbfc6bd94a3f633d02089c2c1ea0b8ff27%2F6da0bc3f2d_image-SPYCK6P4.webp?alt=media)

where

* ApertureL(t) is the left aperture sample at time t, and ApertureR(t) is the right aperture sample at time t
* BaselineL and BaselineR are the per-eye baselines from the step above.

**Eye closure detection (binary):** At each time t, the following classification is made:

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-2305c30e6cd3a394e63ea8c35c9121ddbd2a7c5d%2Ff36edbe5c9_image-1T22S3U4.webp?alt=media)

where ![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-a110d14ac5f8bd006a329623781eb98b0f5c56c9%2F2e2fdc5c9e_image-TND3BC0C.webp?alt=media)(threshold) is the user-defined threshold (relative to the open-eye baseline).

**Momentary percentage of eye closure (PERCLOS):**

1. **Window generation:** The signal is divided into consecutive windows of the defined length. A new window starts repeatedly based on the defined window increment step, creating an overlap of the size (Moving window length)-(Window increment step) between adjacent windows.
2. **PERCLOS by window:** For each window, the algorithm computes the percentage of samples classified as eye closure detected within that window. When windows overlap, a single eye closure episode can contribute to multiple windows if its samples fall within the overlapping time ranges. This overlap produces smoother transitions between windows and captures episodes that occur near window boundaries.

*Example of binning with overlap (momentary PERCLOS windows):*

*With a window length of 10000 ms and an increment of 1000 ms:*

* ***Window 1**: Start at 0 ms, end at 10000 ms*
* ***Window 2**: Start at 1000 ms, end at 11000 ms*
* ***Window 3**: Start at 2000 ms, end at 12000 ms*

*If an eye closure episode spans from 500 ms to 1200 ms, it will be included in both Window 1 and Window 2.*

## Outputs

#### Signals

After signal processing, you can access the following **new signals in the Respondent Replay:**

Eye Closure

* Eye closure percentage
* Eye closure detected

Momentary PERCLOS

* PERCLOS

#### Markers

In addition to the signals, you can also access **Analysis Markers** indicating the start and end of the classified eye closures.

Under Analysis metrics, you can access statistics on the following metrics:

* Eye closure count
* PERCLOS

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-d73d20807cfa4675a6fff42b2b4d6ed5f7f34e85%2F597e1945c9_image-Q1KJOWLE.webp?alt=media)

## Exported Files

There are four types of files you can export: Sensor Data files, and three types of R processing files:

* Eye closure metrics
* Eye closure table
* Moment to moment PERCLOS

#### Sensor Data

**Sensor Data file**: This is the raw sensor data export. It can also include R-processed signals by ticking the “R analysis Eye tracker PERCLOS” under Sensor Data > Sensors

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-bf52618be29a3c262c2347db026e3aad237a1bed%2F2301635274_image-IP5L6ZQK.webp?alt=media)

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-7e050e6788763f7443e57187ddf976bfe3d9940f%2Faf6e47b42e_image-UHW30HI0.webp?alt=media)

<figure><img src="https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-7255410b9d38f507796040625c13b971cf51fbf0%2Fc5b94b00be_image-IIZVYTTJ.webp?alt=media" alt=""><figcaption><p>Example Sensor Data export file</p></figcaption></figure>

#### R Processing Metrics

**Eye closure metrics:** This file includes the processed results on Eye Closure Count and PERCLOS across respondents and stimuli/ time intervals.

**Eye closure table:** This file lists the detected eye closures with an index number, onset, offset, and duration of each eye closure, also indicating during which stimulus/ annotation/ scene it happened. You will find a column called truncation type that will describe whether the identified eye closure is truncated (incomplete for the given stimulus/ scene/ annotation) or whole (complete).

**Moment to moment PERCLOS:** This file lists every epoch of the moving window along with the start and end time stamps and duration, as well as the PERCLOS metric during the epoch.

You can access the exported files by

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-42062f018aab1ce8f175ab13f2f3669999a2f4ed%2Fda220abd04_image-ARGLCDS9.webp?alt=media)

(1) clicking on the ‘Export’ button,

(2) under ‘R PROCESSING’, you can

(3) select to have individual metrics exports (to obtain a separate export file per modality) or a Single multi-modal export (relevant when you use more than one modality), you can click on

(4) ‘Eyetracker PERCLOS Export’. Here, by expanding the accordion menu, you can access further options.

(5) When you finally click the blue Export button, you will export the three PERCLOS exports, which can look as follows:

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-7a21f70a9e6ab0bd32bd6153da2dabc16af1ff25%2Fe002dacf59_image-VIS98H9T.webp?alt=media)

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-98ae4d3a07c6078ea3eec0f7d823da997332542a%2F06e12dac4c_image-963JZINP.webp?alt=media)

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-3750c0d84f85f62c0539a3afd593ddea6c56c956%2F22a4ae5c26_image-P8O0GY18.webp?alt=media)

#### PERCLOS Metrics Descriptions

| PERCLOS           | Percentage of the interval's duration during which eye closure was detected. |
| ----------------- | ---------------------------------------------------------------------------- |
| Eye closure count | Count of eye closures detected during this interval.                         |

Description of the PERCLOS signals in SensorData:

| Eye Closure Percentage | Percentage of eye closure relative to maximum eye openness during baseline.                                                                                                                 |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Eye Closure Detected   | Binary signal, where eye closure samples falling within the onset and offset of the detected eye closure are assigned a value of 1. Samples outside eye closures are assigned a value of 0. |
| PERCLOS                | The momentary percentage of eye closure.                                                                                                                                                    |

## Reports

When clicking the Reports button, you can access the entire description of the signal processing steps along with additional tables and plots.

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-6916dd7fed22b796c6633d436da7c6a8a3871752%2F3008ada08d_image-9A3OU4NB.webp?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.imotions.com/lab/analysis/biosensor-analysis/r-notebooks-perclos-percentage-of-eye-closure.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
