Accelerated implementations of the PSNR-HVS, PSNR-HVS-M, PSNR-HA and PSNR-HMA image metrics

psnr, hvs, video, image, metric
pip install psnr-hvsm==0.1.0


cibuildwheel python_versions pypi license


Accelerated Python package for computing several image metrics based on human perception.

This is an implementation of the PSNR-HVS, PSNR-HVS-M, PSNR-HA and PSNR-HMA metrics developed by Nikolay Ponomarenko.

The values produced by this library have been cross-checked against the results within the TID2013 dataset. (See the folder tid2013_results.) The only difference is that this library follows the common convention that PSNR for identical signals equals 100.0.

A miniscule discrepancy for PSNR-HMA (<0.01dB on average) is under investigation.



psnr_hvsm supports Python 3.6-3.9. Packages are distributed on PyPi. Be sure to have an up-to-date pip to be able to install the correct packages on Linux:

python -m pip install --upgrade pip
pip install psnr_hvsm


Command line

Command line support is an extra that pulls opencv-python-headless:

pip install psnr_hvsm[command_line]
python -m psnr_hvsm original.png distorted.png

As a library

The function psnr_hvs_hvsm accepts images as single-channel floating-point NumPy arrays. The images need to be normalised, i.e. the values need to be in the range [0,1]. This can be achieved by converting the image to float and dividing by the maximum value given the bit depth. For 8 bits per component this is 255.

The images must be padded to a multiple of 8 in each dimension.

from imageio import imread
from psnr_hvsm import psnr_hvs_hvsm

image1 = imread('tests/baboon.png').astype(float) / 255
image2 = imread('tests/baboon_msk.png').astype(float) / 255

psnr_hvs, psnr_hvsm = psnr_hvs_hvsm(image1, image2)

print(psnr_hvs, psnr_hvsm)
34.427054505764424 51.64722121999962

If you need to measure PSNR-HVS and PSNR-HVS-M on an RGB image, you need to convert it to an YUV colorspace and pass in only the luma component.

Computing metrics for the TID2013 dataset

If you have a copy of the TID2013 dataset, you can re-verify the metrics for yourself:

python -m psnr_hvsm.tid2013_metrics D:\tid2013\ .\tid2013_results\

Other exported functions

  • psnr_hvs - returns only the PSNR-HVS value
  • psnr_hvsm - returns only the PSNR-HVS-M value
  • hvs_mse_tile - compute the weighted MSE of two 8x8 tiles
  • hvsm_mse_tile - compute the weighted MSE with masking correction of two 8x8 tiles
  • hvs_mse - compute HVS scores on all 8x8 tiles in the images, returns an array of numbers
  • hvsm_mse - compute HVS-M scores on all 8x8 tiles in the images, returns an array of numbers



psnr_hvsm has several dependencies:

All of the above can be automatically resolved by running deps.ps1, which is a cross-platform PowerShell script (i.e. it can also be run under Linux if you have PowerShell installed).

Development mode

To install in development mode:

pip install --upgrade -r requirements.txt

Creating Python wheel

pip install --upgrade -r requirements-build.txt
python bdist_wheel

Running tests on different versions of Python using tox

pip install --upgrade -r requirements-tox.txt
tox --parallel auto