Skip to main content

License GitHub top language GitHub stars PyPI - Python Version PyPI

Bjøntegaard-Delta Interpolation

BD-rate implementations in Python. Also available in Matlab.

Introduction

The Bjøntegaard-Delta (BD) metrics (delta bit rate and delta PSNR) described in [1] are well known metrics to measure the average differences between two rate-distortion (RD) curves. They are based on cubic-spline interpolation (CSI) of the RD curves and Matlab as well as Python implementations are available on the internet.

However, this way of interpolation using a third-order polynomial leads to problems for certain RD curve constellations and causes very misleading results. This has also been experienced during the standardization of HEVC. Consequently, the so-called piecewise cubic hermite interpolation (PCHIP) has been implemented in the JCT-VC Common Test Conditions (CTC) Excel sheet [2] for performance evaluation. In further studies [4] - [5], it was found that Akima interpolation returns more accurate and stable results. An example for corresponding interpolated curves is shown below.

This page provides BD-rate implementations (see here for a Matlab implementation) for both cubic-spline interpolation, PCHIP, and Akima interpolation in Python. In our tests, the implementation of PCHIP returns the same value as the Excel-Implementation from [3] with an accuracy of at least 10 decimal positions. The scripts allow to calculate the BD-rate for any number of RD points greater one.

Install

bjontegaard is best installed via pip: pip install bjontegaard.

Usage

Basic example with test data measured using ffmpeg (libx265 with different preset settings) and Akima interpolation:

# Import the package
import bjontegaard as bd

# Test data
rate_anchor = [9487.76, 4593.60, 2486.44, 1358.24]
psnr_anchor = [ 40.037,  38.615,  36.845,  34.851]
rate_test = [9787.80, 4469.00, 2451.52, 1356.24]
psnr_test = [ 40.121,  38.651,  36.970,  34.987]

# Use the package
bd_rate = bd.bd_rate(rate_anchor, psnr_anchor, rate_test, psnr_test, method='akima')
bd_psnr = bd.bd_psnr(rate_anchor, psnr_anchor, rate_test, psnr_test, method='akima')

print(f"BD-Rate: {bd_rate:.4f} %")
print(f"BD-PSNR: {bd_psnr:.4f} dB")

This package provides two main functions for BD metric calculation:

  • bd_rate(rate_anchor, dist_anchor, rate_test, dist_test, method, require_matching_points=True, interpolators=False)
  • bd_psnr(rate_anchor, dist_anchor, rate_test, dist_test, method, require_matching_points=True, interpolators=False)

The parameters rate_anchor and dist_anchor describe the rate-distortion points of the anchor, rate_test and dist_test describe the rate-distortion points of the test codec.

Available interpolation methods:

  • 'cubic': Cubic spline interpolation
  • 'pchip': Piecewise cubic hermite interpolation (used in standardizations [2], [3])
  • 'akima': Akima interpolation [4]

If require_matching_points=True (default), the number of rate-distortion points for anchor and test must match. If interpolators=True is given, the functions additionally return the internal interpolation objects that can be used to check the behaviour of the value interpolation.

Relative curve difference plots (RCD-plots)

For in-depth evaluation of codec comparison results, we recommend to take relative curve difference plots (RCD-plots) into account (see [5]). They can be created using:

  • plot_rcd(rate_anchor, dist_anchor, rate_test, dist_test, method, require_matching_points=True, samples=1000)

Here is an example for a RCD plot.

Relative curve difference

The left plot shows the supporting points and the Akima-interpolated curves for both anchor and test. The right plot shows the relative horizontal difference between the two curves in percentage.

Comparison behind the scenes

The function compare_methods generates a plot that compares the internal interpolation behaviour of the three variants. The parameters rate_label, distortion_label, and figure_label control the figure and axis labels of the plot. If filepath is given, the final figure is saved to this file.

import bjontegaard as bd

# Test data
rate_anchor = [9487.76, 4593.60, 2486.44, 1358.24]
psnr_anchor = [ 40.037,  38.615,  36.845,  34.851]
rate_test = [9787.80, 4469.00, 2451.52, 1356.24]
psnr_test = [ 40.121,  38.651,  36.970,  34.987]

# Compare the internal behaviour of the three variants
bd.compare_methods(rate_anchor, psnr_anchor, rate_test, psnr_test, rate_label="Rate", distortion_label="PSNR", figure_label="Test 1", filepath=None)

Furthermore, a comparison between the interpolated curves and intermediate, true rate-distortion points between the supporting points is shown in the plot below. For this example, the quality is represented by the SSIM value. Note that the example was cherry-picked to show that cubic interpolation can fail. The curve interpolated by the Akima interpolator is closest to the intermediate points.

Measured data

References

[1] G. Bjontegaard, "Calculation of average PSNR differences between RD-curves", VCEG-M33, Austin, TX, USA, April 2001.
[2] F. Bossen, "Common HM test conditions and software reference configurations", JCTVC-L1100, Geneva, Switzerland, April 2013.
[3] F. Bossen, "VTM common test conditions and software reference configurations for SDR video", JVET-T2020, Teleconference, October 2020.
[4] C. Herglotz, M. Kränzler, R. Mons, A. Kaup, "Beyond Bjontegaard: Limits of Video Compression Performance Comparisons", Proc. International Conference on Image Processing (ICIP) 2022, online available.
[5] C. Herglotz, H. Och, A. Meyer, G. Ramasubbu, L. Eichermüller, M. Kränzler, F. Brand, K. Fischer, D. T. Nguyen, A. Regensky, and A. Kaup, “The Bjøntegaard Bible – Why Your Way of Comparing Video Codecs May Be Wrong,” preprint available, 2023.

License

BSD 3-Clause. For details, see LICENSE.

Metadata

Release files for bjontegaard 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bjontegaard 1.3.0
File Size Uploaded Provenance
bjontegaard-1.3.0.tar.gz 12.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bjontegaard 1.3.0
File Interpreter ABI Platform
bjontegaard-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.7 kB

Release files / bjontegaard-1.3.0.tar.gz

Download URL bjontegaard-1.3.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7b25a5b709c81b6150f8eb70de407a7ab2d84260741b24b1f96e403ee2ce1698
BLAKE2b-256 checksum
How to use checksums
282b1d3304d3721e23a90fab8c141d46d8e406a0f47b406abdbb7472a1094eb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / bjontegaard-1.3.0-py3-none-any.whl

Download URL bjontegaard-1.3.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df8c0934ea505b80392126adefcb6fb5b2c747313a50cba69f3e5973dd8b2e5e
BLAKE2b-256 checksum
How to use checksums
ada69435bfae84b25bdb77ca0fcbdf1dea204636e9d618c584db5416461691b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for bjontegaard 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page