Skip to main content

A Python package for volumetric image quality assessment.

Project description

Logo for vIQA: A cube with three slices colored in red, green and blue in one direction and three slices colored in black, gray and white in another direction.

vIQA — volumetric Image Quality Assessment


Project Status: Active – The project has reached a stable, usable state and is being actively developed. PyPI - Version PyPI - Python Version PyPI - License PyPI - Downloads Documentation GH Action Build GH Action pre-commit pre-commit.ci status Ruff Binder Contributor Covenant

Table of Contents

vIQA provides an extensive assessment suite for image quality of 2D-images or 3D-volumes as a python package. Image Quality Assessment (IQA) is a field of research that aims to quantify the quality of an image. This is usually done by comparing the image to a reference image (full-reference metrics), but can also be done by evaluating the image without a reference (no-reference metrics). The reference image is usually the original image, but can also be another image that is considered to be of high quality. The comparison is done by calculating a metric that quantifies the difference between the two images or for the image itself. These quality metrics are used in various fields, such as medical imaging, computer vision, and image processing. For example the efficiency of image compression algorithms can be evaluated by comparing the compressed image to the original image. This package implements several metrics to compare two images or volumes using different IQA metrics. In addition, some metrics are implemented that can be used to evaluate a single image or volume.

The metrics used are:

  • Peak Signal to Noise Ratio (PSNR)
  • Root Mean Square Error (RMSE)
  • Universal Quality Index (UQI) [^1]
  • Structured Similarity (SSIM) [^2]
  • Multi-Scale Structural Similarity (MS-SSIM) [^3]
  • Feature Similarity Index (FSIM) [^4]
  • Visual Information Fidelity in pixel domain (VIFp) [^5]

[!CAUTION] The calculated values for VIFp are probably not correct in this implementation. Those values should be treated with caution as further testing is required.

  • Visual Saliency Index (VSI) [^6]

[!WARNING] The original metric supports RGB images only. This implementation can work with grayscale images by copying the luminance channel 3 times.

  • Most Apparent Distortion (MAD) [^7]
  • Gradient Similarity Measure (GSM) [^8]

[!CAUTION] This metric is not yet tested. The metric should be only used for experimental purposes.

  • Contrast to Noise Ratio (CNR) [^9]
  • Signal to Noise Ratio (SNR)
  • Q-Measure [^10]

Overview

Metric Name Type Dimensional behaviour Colour Behaviour Range (different/worst - identical/best) Tested Validated Reference
PSNR Peak Signal to Noise Ratio FR 3D native ✔️ $[0, \infty)$ ✔️ ✔️
RMSE Root Mean Square Error FR 3D native ✔️ $(\infty, 0]$ ✔️ ✔️
UQI [^a] Universal Quality Index FR 3D native (✔️) [^b] $[-1, 1]$ (✔️) [^c] [^1]
SSIM Structured Similarity FR 3D native (✔️) [^b] $[-1, 1]$ [^d] ✔️ ✔️ [^2]
MS-SSIM Multi-Scale Structural Similarity FR 3D slicing $[0, 1]$ ✔️ [^3]
FSIM Feature Similarity Index FR 3D slicing ✔️ $[0, 1]$ ✔️ ✔️ [^4]
VIFp Visual Information Fidelity in pixel domain FR 3D slicing $[0, \infty)$ [^e] [^5]
VSI Visual Saliency Index FR 3D slicing ✔️ [^f] $[0, 1]$ [^6]
MAD Most Apparent Distortion FR 3D slicing $[0, \infty)$ ✔️ [^7]
GSM Gradient Similarity FR 3D native or slicing $[0, 1]$ [^8]
CNR Contrast to Noise Ratio NR 3D native $[0, \infty)$ ✔️ [^9]
SNR Signal to Noise Ratio NR 3D native ✔️ $[0, \infty)$ ✔️
Q-Measure Q-Measure NR 3D only [^g] $[0, \infty)$ [^10]

[^a]: UQI is a special case of SSIM. Also see [^2]. [^b]: The metric is calculated channel-wise for color images. The values are then averaged after weighting. [^c]: As UQI is a special case of SSIM, the validation of SSIM is also valid for UQI. [^d]: The range for SSIM is given as $[-1, 1]$, but is usually $[0, 1]$ in practice. [^e]: Normally $[0, 1]$, but can be higher than 1 for modified images with higher contrast than reference images. [^f]: The original metric supports RGB images only. This implementation can work with grayscale images by copying the luminance channel 3 times. [^g]: The Q-Measure is a special metric designed for CT images. Therefore it only works with 3D volumes.

Documentation

The API documentation can be found here.

Requirements

The following packages have to be installed:

  • matplotlib
  • nibabel
  • numpy
  • piq
  • pytorch
  • scikit-image
  • scipy
  • tqdm
  • (jupyter) if you want to use the provided notebook

Installation

Use either pip

pip install viqa

or conda

conda install -c conda-forge viqa

[!IMPORTANT] The package is currently in development and not yet available on conda-forge.

Usage

Workflow

Images are first loaded from .raw files or .mhd files and their corresponding .raw file, normalized to the chosen data range (if the parameter normalize=True is set) and then compared. The scores are then calculated and can be printed. If using paths file names need to be given with the bit depth denoted as a suffix (e.g. _8bit.raw, _16bit.mhd) and the dimensions of the images need to be given in the file name (e.g. 512x512x512). The images are assumed to be grayscale. Treatment of color images is planned for later versions. The metrics are implemented to calculate the scores for an 8-bit data range (0-255) per default. For some metrics the resulting score is different for different data ranges. When calculating several metrics for the same image, the same data range should be used for all metrics. The data range can be changed by setting the parameter data_range for each metric. This parameter primarily affects the loading behaviour of the class instances when not using the vIQA.utils.load_data function directly as described further below, but for some metrics setting the data range is necessary to calculate the score (e.g. PSNR).

Examples

Better:

import viqa
from viqa import load_data, normalize_data

## load images
file_path_img_r = 'path/to/reference_image_8bit_512x512x512.raw'
file_path_img_m = 'path/to/modified_image_8bit_512x512x512.raw'
img_r = load_data(
  file_path_img_r,
  data_range=1,
  normalize=False,
)  # data_range ignored due to normalize=False
img_m = load_data(file_path_img_m)  # per default: normalize=False
# --> both images are loaded as 8-bit images

# calculate and print RMSE score
rmse = viqa.RMSE()
score_rmse = rmse.score(img_r, img_m)  # RMSE does not need any parameters
rmse.print_score(decimals=2)

# normalize to 16-bit
img_r = normalize_data(img_r, data_range_output=(0, 65535))
img_m = load_data(img_m, data_range=65535, normalize=True)
# --> both functions have the same effect

# calculate and print PSNR score
psnr = viqa.PSNR(data_range=65535)  # PSNR needs data_range to calculate the score
score_psnr = psnr.score(img_r, img_m)
psnr.print_score(decimals=2)

# set optional parameters for MAD as dict
calc_parameters = {
    'block_size': 16,
    'block_overlap': 0.75,
    'beta_1': 0.467,
    'beta_2': 0.130,
    'luminance_function': {'b': 0, 'k': 0.02874, 'gamma': 2.2},
    'orientations_num': 4,
    'scales_num': 5,
    'weights': [0.5, 0.75, 1, 5, 6]
}

# calculate and print MAD score
mad = viqa.MAD(data_range=65535)  # MAD needs data_range to calculate the score
score_mad = mad.score(img_r, img_m, dim=2, **calc_parameters)
mad.print_score(decimals=2)

Possible, but worse (recommended only if you want to calculate a single metric):

import viqa

file_path_img_r = 'path/to/reference_image_512x512x512_16bit.raw'
file_path_img_m = 'path/to/modified_image_512x512x512_16bit.raw'

load_parameters = {'data_range': 1, 'normalize': True}
# data_range is set to 1 to normalize the images
# to 0-1 and for calculation, if not set 255 would
# be used as default for loading and calculating
# the score

psnr = viqa.PSNR(**load_parameters)  # load_parameters necessary due to direct loading by class
# also PSNR needs data_range to calculate the score
# if images would not be normalized, data_range should be
# 65535 for 16-bit images for correct calculation
score = psnr.score(file_path_img_r, file_path_img_m)
# --> images are loaded as 16-bit images and normalized to 0-1 via the `load_data` function
#     called by the score method
psnr.print_score(decimals=2)

[!TIP] It is recommended to load the images directly with the vIQA.utils.load_data function first and then pass the image arrays to the metrics functions. You can also pass the image paths directly to the metrics functions. In this case, the images will be loaded with the given parameters. This workflow is only recommended if you want to calculate a single metric.

[!IMPORTANT] The current recommended usage files are: Image_Comparison.ipynb and Image_comparison_batch.ipynb.

For more examples, see the provided Jupyter notebooks and the documentation under API Reference.

TODO

  • Add metrics
    • Add SFF/IFS
    • Add Ma
    • Add PI
    • Add NIQE
  • Add tests
    • Add tests for RMSE
    • Add tests for PSNR
    • Add tests for SSIM
    • Add tests for MSSSIM
    • Add tests for FSIM
    • Add tests for VSI
    • Add tests for VIF
    • Add tests for MAD
    • Add tests for GSM
    • Add tests for CNR
    • Add tests for SNR
    • Add tests for Q-Measure
  • Add support for different data ranges
  • Validate metrics
  • Add color image support
  • Add support for printing values
    • Add support for .txt files
    • Add support for .csv files
  • Add support for fusions
    • Add support for linear combination
    • Add support for decision fusion

Contributing

See CONTRIBUTING.md for information on how to contribute to the project and development guide for further information.

License

BSD 3-Clause

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Contacts

Lukas Behammer, lukas.behammer@fh-wels.at

References

[^1]: Wang, Z., & Bovik, A. C. (2002). A Universal Image Quality Index. IEEE SIGNAL PROCESSING LETTERS, 9(3). https://doi.org/10.1109/97.995823 [^2]: Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13(4), 600–612. https://doi.org/10.1109/TIP.2003.819861 [^3]: Wang, Z., Simoncelli, E. P., & Bovik, A. C. (2003). Multi-scale structural similarity for image quality assessment. The Thirty-Seventh Asilomar Conference on Signals, Systems & Computers, 1298–1402. https://doi.org/10.1109/ACSSC.2003.1292216 [^4]: Zhang, L., Zhang, L., Mou, X., & Zhang, D. (2011). FSIM: A feature similarity index for image quality assessment. IEEE Transactions on Image Processing, 20(8). https://doi.org/10.1109/TIP.2011.2109730 [^5]: Sheikh, H. R., & Bovik, A. C. (2006). Image information and visual quality. IEEE Transactions on Image Processing, 15(2), 430–444. https://doi.org/10.1109/TIP.2005.859378 [^6]: Zhang, L., Shen, Y., & Li, H. (2014). VSI: A visual saliency-induced index for perceptual image quality assessment. IEEE Transactions on Image Processing, 23(10), 4270–4281. https://doi.org/10.1109/TIP.2014.2346028 [^7]: Larson, E. C., & Chandler, D. M. (2010). Most apparent distortion: full-reference image quality assessment and the role of strategy. Journal of Electronic Imaging, 19 (1), 011006. https://doi.org/10.1117/1.3267105 [^8]: Liu, A., Lin, W., & Narwaria, M. (2012). Image quality assessment based on gradient similarity. IEEE Transactions on Image Processing, 21(4), 1500–1512. https://doi.org/10.1109/TIP.2011.2175935 [^9]: Desai, N., Singh, A., & Valentino, D. J. (2010). Practical evaluation of image quality in computed radiographic (CR) imaging systems. Medical Imaging 2010: Physics of Medical Imaging, 7622, 76224Q. https://doi.org/10.1117/12.844640 [^10]: Reiter, M., Weiß, D., Gusenbauer, C., Erler, M., Kuhn, C., Kasperl, S., & Kastner, J. (2014). Evaluation of a Histogram-based Image Quality Measure for X-ray computed Tomography. 5th Conference on Industrial Computed Tomography (iCT) 2014, 25-28 February 2014, Wels, Austria. e-Journal of Nondestructive Testing Vol. 19(6). https://www.ndt.net/?id=15715

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

viqa-2.0.2.tar.gz (155.3 kB view details)

Uploaded Source

Built Distributions

viqa-2.0.2-cp312-cp312-win_amd64.whl (202.6 kB view details)

Uploaded CPython 3.12 Windows x86-64

viqa-2.0.2-cp312-cp312-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

viqa-2.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (262.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

viqa-2.0.2-cp312-cp312-macosx_13_3_x86_64.whl (146.8 kB view details)

Uploaded CPython 3.12 macOS 13.3+ x86-64

viqa-2.0.2-cp312-cp312-macosx_13_3_arm64.whl (140.5 kB view details)

Uploaded CPython 3.12 macOS 13.3+ ARM64

viqa-2.0.2-cp311-cp311-win_amd64.whl (202.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

viqa-2.0.2-cp311-cp311-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

viqa-2.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (262.5 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

viqa-2.0.2-cp311-cp311-macosx_13_3_x86_64.whl (146.8 kB view details)

Uploaded CPython 3.11 macOS 13.3+ x86-64

viqa-2.0.2-cp311-cp311-macosx_13_3_arm64.whl (140.5 kB view details)

Uploaded CPython 3.11 macOS 13.3+ ARM64

File details

Details for the file viqa-2.0.2.tar.gz.

File metadata

  • Download URL: viqa-2.0.2.tar.gz
  • Upload date:
  • Size: 155.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for viqa-2.0.2.tar.gz
Algorithm Hash digest
SHA256 0f4d55c99f5cf3cbd5dadb569f28a692821fdf0fd823739c34e6e899a52a2a83
MD5 76ff3dcc8d1e3c24a43ab24ae38cb822
BLAKE2b-256 34281afe9e1071f0e52ecf7134745046cd6a859c526e86ae83cbbd194d32fb9b

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: viqa-2.0.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 202.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for viqa-2.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a512a61d82370ad3279ce0cc72dceb1bb6d541fb7a51ac482c0210a87458036b
MD5 c0128615759a68d13c221e0b5364021b
BLAKE2b-256 35b431b3339a99272a851705dfcef616473561eda3454fbf2c017eb003f9fbf3

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4f8bf671a09da1114f6b3e97d746570a23f12c68267f5347ede75b5b3fc762a8
MD5 626890106e015fd93690b3d50b784dca
BLAKE2b-256 49281dbf49aea2c3c3a433a0e89a10c224c046a3105a6353a4849f1c1838b2ea

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3a227b14d10e0f999dae1e25843f96776686e3e9a4a3f3af6b1d2ef89f47c75b
MD5 0bcc9e5ea98038258cb34b33395824b9
BLAKE2b-256 b6e43c43a26e24dd5e9cb033856c2af8cfc49bf7d6bb3203acf2df0138136309

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp312-cp312-macosx_13_3_x86_64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp312-cp312-macosx_13_3_x86_64.whl
Algorithm Hash digest
SHA256 d5e93be151dd0d512915dc963047ca7ef07fe3284d232870ec31788149c99775
MD5 e9cc91889be365d1621ee989cc0beacc
BLAKE2b-256 d2defed22f9be7ce2794aa727e2dcd5a6aa4de930078692ac0500fb919e8a172

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp312-cp312-macosx_13_3_arm64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp312-cp312-macosx_13_3_arm64.whl
Algorithm Hash digest
SHA256 5b024e35be83b968cf0311cd023307a4f4c7f89af6b1c5acbdc35e585366d37f
MD5 737d99e8141382fbf1240cec9e035da8
BLAKE2b-256 22238dfb63eab2758aa9d4dbc3f81344b1ab1b33d45df38f89764cad075c8e3c

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: viqa-2.0.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 202.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for viqa-2.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 824f5920d8c8cb18c4d2cb6f536cf738cf61905f911ef6667a61fd257f50f96e
MD5 2dfec7d19b7be300e81a5917f7060ded
BLAKE2b-256 c31e81d3004601127caa92bbcf8c37ecf1d218210b6d0ccf4394ceb8453c2141

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0ccfcfdb65168d9d51a6c2405a66ba5edc348e8aee1f17b9e620da371a8229b8
MD5 986a2c5c5aece1cd681a5789e48c2720
BLAKE2b-256 4827290ce9b5ee8de92377fbf328f5717412d86d4f6013c44bf20ef0520df294

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e85db4e7b2979513a9a19a7e2a9a62f4000f78bc39ecbd0959c505a7e2551032
MD5 0ce5321d4f525b73e13719dc4ef9cb09
BLAKE2b-256 a13b267cb877f3de2de41ef90f075ecbd238ebd6da2b008a5c0aa1e0e9b76610

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp311-cp311-macosx_13_3_x86_64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp311-cp311-macosx_13_3_x86_64.whl
Algorithm Hash digest
SHA256 83d7f8bbb7f7ce9d341546dc68eeaa3cdca599a98579857cc724fb71955713aa
MD5 868fb100fd69b4e2574fd6a65e602231
BLAKE2b-256 4c1f7907331b459f4f334defe1594ffdafc309bd4bc2cc516f3da287f566b838

See more details on using hashes here.

Provenance

File details

Details for the file viqa-2.0.2-cp311-cp311-macosx_13_3_arm64.whl.

File metadata

File hashes

Hashes for viqa-2.0.2-cp311-cp311-macosx_13_3_arm64.whl
Algorithm Hash digest
SHA256 599937f21adcaaa32ca6067cc3205d8af9df696306e0dccce0f3b97a6d3e7fa3
MD5 69aefa6a1e2b2f20a259c0baff91584c
BLAKE2b-256 1eb79d36881e38a7b575c1f915674fcbc2e6649052e6e3f88988968bc484c835

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page