Package: psnr-hvsm
PSNR-HVS-M, PSNR-HA and PSNR-HMA metrics for NumPy and PyTorchAccelerated Python package for computing several image metrics based on human
perception with backends in NumPy, PyTorch and C++.This is an implementation of the PSNR-HVS, PSNR-HVS-M, PSNR-HA and PSNR-HMA
metrics developed byNikolay Ponomarenko.The values produced by this library have been cross-checked against the results
within theTID2013 dataset.
(See the foldertid2013_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.BibliographyEgiazarian, Karen, et al. "New full-reference quality metrics based on HVS." Proceedings of the Second International Workshop on Video Processing and Quality Metrics. Vol. 4. 2006.Ponomarenko, Nikolay, et al. "On between-coefficient contrast masking of DCT basis functions." Proceedings of the third international workshop on video processing and quality metrics. Vol. 4. 2007.Ponomarenko, Nikolay, et al. "Modified image visual quality metrics for contrast change and mean shift accounting." 2011 11th International Conference The Experience of Designing and Application of CAD Systems in Microelectronics (CADSM). IEEE, 2011.Installationpsnr_hvsmsupports Python 3.7-3.11. 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-mpipinstall--upgradepippipinstallpsnr_hvsmUsageCommand lineCommand line support is an extra that pullsimageio:pipinstallpsnr_hvsm[command_line]python-mpsnr_hvsmoriginal.pngdistorted.pngChoosing a backendThe backend can be set by setting thePSNR_HVSM_BACKENDenvironment variable.
Valid backends are:numpy- pure NumPycpp- C++ using FFTW3torch- PyTorch; install aspsnr_hvsm[torch]to install PyTorch as wellexportPSNR_HVSM_BACKEND=torch
python-mpsnr_hvsmoriginal.pngdistorted.pngThe default device for PyTorch iscudabut it can be changed by setting thePSNR_HVSM_TORCH_DEVICEenvironment variable.As a libraryThe functionpsnr_hvs_hvsmaccepts 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 tofloatand
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.fromimageioimportimreadfrompsnr_hvsmimportpsnr_hvs_hvsm,bt601ycbcrimage1=imread('tests/baboon.png').astype(float)/255image2=imread('tests/baboon_msk.png').astype(float)/255image1_y,*_=bt601ycbcr(image1)image2_y,*_=bt601ycbcr(image2)psnr_hvs,psnr_hvsm=psnr_hvs_hvsm(image1,image2)print(psnr_hvs,psnr_hvsm)34.42705450576442451.64722121999962If 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.PyTorch supportThe PyTorch backend can be used for use with gradient descent algorithms and
computation on GPUs. In order to use the PyTorch backend, either install the
package with thetorchextra:pipinstallpsnr_hvsm[torch]If your PyTorch installation was manual, you needtorch-dctin order to use the PyTorch
backend:pipinstall"torch-dct>=0.1.6"An important distinction is that the functions that expect 3-channel input now
expect(...,C,H,W)format in the PyTorch implementation. The PyTorch backend
can be enabled by importing it directly frompsnr_hvsm.torch:importtorchfromimageioimportimreadfrompsnr_hvsm.torchimportpsnr_hvs_hvsm,bt601ycbcrimage1=imread('tests/baboon.png').astype(float)/255image2=imread('tests/baboon_msk.png').astype(float)/255image1=torch.tensor(image1,device='cuda').moveaxis(-1,-3)# convert to (N,C,H,W) formatimage2=torch.tensor(image2,device='cuda').moveaxis(-1,-3)# convert to (N,C,H,W) formatimage1_y,*_=bt601ycbcr(image1)image2_y,*_=bt601ycbcr(image2)psnr_hvs,psnr_hvsm=psnr_hvs_hvsm(image1_y,image2_y)Alternatively, set thePSNR_HVSM_BACKENDenvironment variable totorch:importosos.environ['PSNR_HVSM_BACKEND']='torch'frompsnr_hvsmimportpsnr_hvs_hvsm# rest of code# ...Computing metrics for the TID2013 datasetIf you have a copy of theTID2013 dataset,
you can re-verify the metrics for yourself:python-mpsnr_hvsm.tid2013_metricsD:\tid2013\.\tid2013_results\Other exported functionshvs_hvsm_mse_tiles- compute HVS and HVS-M scores on all 8x8 tiles in the
images, returns an array of numbershvs_hvsm_mse- compute average HVS and HVS-M scoresBuildingDependenciespsnr_hvsmhas several dependencies:FFTW3 >= 3.3.9pybind11xtensorxtensor-pythonFFTW3 is automatically resolved by CMake and the rest can be installed by
creating acondaenvironment using the provided YAML file:condaenvcreate-fpsnr_hvsm-dev.ymlDevelopment modeTo install in development mode:pipinstall--upgrade-rrequirements.txtCreating Python wheelpipinstall--upgrade-rrequirements-build.txt
pythonsetup.pybdist_wheelRunning tests on different versions of Python using toxpipinstall--upgrade-rrequirements-tox.txt
tox--parallelauto