siti 1.4.5
Calculate Spatial Information / Temporal Information according to ITU-T P.910
License: MIT
Requires Python: >=3.7
Keywords: video,spatial information,temporal information

# SITI: Spatial Information / Temporal Information

[![PyPI version](https://img.shields.io/pypi/v/siti.svg)](https://pypi.org/project/siti/)

[![Python package](https://github.com/slhck/siti/actions/workflows/python-package.yml/badge.svg)](https://github.com/slhck/siti/actions/workflows/python-package.yml)

A command-line-based tool to calculate spatial information (SI) and temporal information (TI) according to ITU-T P.910.

The command outputs SI and TI information to stdout, in JSON format, or alternatively as CSV.

Author: Werner Robitza

**Important Note / Breaking Changes:**

* Version 1.4 does not include the 0 TI value for global statistics calculation
* Version 1.3 fixes an issue with border handling, now returning values that should better match ITU-T Rec. P.910. Thanks to Cosmin Stejerean for raising these issues.
* Version 1.x now outputs the same number of values for SI and TI, inserting a null value for the first frame's TI. Also, the output format has been changed.

Contents:

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Background](#background)
  - [Spatial Information](#spatial-information)
  - [Temporal information](#temporal-information)
- [License](#license)

## Requirements

- Python 3.7 or higher
- FFmpeg libraries (to run `pyav`)

Under Ubuntu, to get ffmpeg libraries:

    sudo apt install libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libavfilter-dev libswscale-dev libavresample-dev

Under macOS, it is recommended to install ffmpeg via [Homebrew](https://brew.sh):

    brew install ffmpeg

## Installation

Run:

    pip3 install --user siti

Alternatively, clone this repository and then:

    pip3 install --user .

## Usage

Simply run `siti /path/to/file.mp4`.

Detailed usage:

```
siti [-h] [-of {json,csv}] [-q] [-n NUM_FRAMES] [--width WIDTH] [--height HEIGHT] input

positional arguments:
  input                 input file

optional arguments:
  -h, --help            show this help message and exit
  -of {json,csv}, --output-format {json,csv}
                        output format
  -q, --quiet           do not show progress bar
  -n NUM_FRAMES, --num-frames NUM_FRAMES
                        number of frames to calculate
  --width WIDTH         frame width (for YUV files)
  --height HEIGHT       frame height (for YUV files)
  -f, --full-range      assume full range for YUV input
```

## Background

The following info is given about SI / TI in ITU-T Recommendation P.910 ("Subjective video quality assessment methods for multimedia applications"):

### Spatial Information

> The spatial perceptual information (SI) is based on the Sobel filter. Each video frame (luminance plane) at time n (Fn) is first filtered with the Sobel filter [Sobel(Fn)]. The standard deviation over the pixels (stdspace) in each Sobel-filtered frame is then computed. This operation is repeated for each frame in the video sequence and results in a time series of spatial information of the scene. The maximum value in the time series (maxtime) is chosen to represent the spatial information content of the scene. This process can be represented in equation form as:

> ![](http://i.imgur.com/zRXcVJO.png)

### Temporal information

> The temporal perceptual information (TI) is based upon the motion difference feature, Mn(i, j), which is the difference between the pixel values (of the luminance plane) at the same location in space but at successive times or frames. Mn(i, j) as a function of time (n) is defined as:

> ![](http://i.imgur.com/MRsJtdT.png)

> here Fn(i, j) is the pixel at the ith row and jth column of nth frame in time.
The measure of temporal information (TI) is computed as the maximum over time (maxtime) of the standard deviation over space (stdspace) of Mn(i, j) over all i and j.

> <img src="https://i.imgur.com/XAnKWJw.png" height="19">

> More motion in adjacent frames will result in higher values of TI

## License

siti, Copyright (c) 2017-2019 Werner Robitza

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


# Changelog


## v1.4.5 (2022-05-25)

* Remove dependency on siti_tools.


## v1.4.4 (2022-05-03)

* More strict requirements check.


## v1.4.3 (2022-03-14)

* Handle full range for container reading.


## v1.4.2 (2021-12-13)

* Include siti_tools in setup.py.

* Pypi badge links to pypi (#9)


## v1.4.1 (2021-03-10)

* Add python_requires to setup.py, remove pytest.

* Add status badge.

* Add GitHub actions tests (#8)


## v1.4.0 (2021-03-08)

* Exclude first 0 TI value from global stats.

* Bump requirements for Python, add link to README.

* Switch to siti_tools library.

* Add vscode to gitignore.

* Remove release script.

* Format setup.py and switch to markdown.

* Update badge URL.

* Fix manifest file.


## v1.3.1 (2021-02-03)

* Fix behavior of -n option.

* Fix comment in release script.


## v1.3.0 (2021-01-29)

* Note breaking changes.

* Update CHANGELOG format.

* Crop frame data to valid pixels to avoid edge effects.

* Add tests for sobel filtering.

* Add macOS hint for homebrew.


## v1.2.0 (2020-10-17)

* Fix documentation.

* Remove unneded import.

* Fix tests.


## v1.1.0 (2020-10-13)

* Update README.

* Merge pull request #5 from slhck/add-yuv.

  add support for YUV

* Add support for YUV.


## v1.0.7 (2020-10-10)

* Fix tests.

* Specify exact version reqs.

* Fix tests approximately.


## v1.0.6 (2020-03-15)

* Fix setup script.


## v1.0.5 (2020-03-15)

* Update release script.

* Python 3.8.

* Rename changelog.


## v1.0.4 (2019-06-16)

* Update release script.

* Update requirements instructions.

  Requirements are installed via pip anyway

* Update README.

  fix info about output format


## v1.0.3 (2019-06-16)

* Update release script.


## v1.0.2 (2019-05-18)

* Add manifest.


## v1.0.1 (2019-05-17)

* Add release script.

* Fix README for usage.


## v1.0.0 (2019-05-12)

* Update to version 1.0.

  This is a major release with fixes for incorrect values read from files.

  Thanks to Henrique Domingues Garcia for the PR on
  Telecommunication-Telemedia-Assessment/SITI which lets us now calculate the
  correct values, at least between those implementations.

* Add pypi badge.


## v0.5 (2019-04-10)

* Bump version.

* Fix invocation of np printoptions.


## v0.4 (2019-01-04)

* Bump version.

* Merge pull request #2 from PolynomialDivision/fix/SI_formula.

  fix SI quote

* Fix SI quote.

* Merge pull request #1 from PolynomialDivision/fix/ti_computation.

  exchange SI formula with TI

* Exchange SI with TI.


## v0.3 (2018-06-12)

* Bump version.

* Handle containers with no frames declared.


## v0.2 (2018-04-12)

* Update calculations.

* Formatting/output updates.

* Add README instructions.


## v0.1 (2017-10-24)

* Initial commit.