basicsr.metrics.niqe

basicsr.metrics.niqe.calculate_niqe(img, crop_border, input_order='HWC', convert_to='y', **kwargs)[source]

Calculate NIQE (Natural Image Quality Evaluator) metric.

Paper: Making a "Completely Blind" Image Quality Analyzer

This implementation could produce almost the same results as the official MATLAB codes: http://live.ece.utexas.edu/research/quality/niqe_release.zip

> MATLAB R2021a result for tests/data/baboon.png: 5.72957338 (5.7296) > Our re-implementation result for tests/data/baboon.png: 5.7295763 (5.7296)

We use the official params estimated from the pristine dataset. We use the recommended block size (96, 96) without overlaps.

Parameters:
  • img (ndarray) – Input image whose quality needs to be computed. The input image must be in range [0, 255] with float/int type. The input_order of image can be ‘HW’ or ‘HWC’ or ‘CHW’. (BGR order) If the input order is ‘HWC’ or ‘CHW’, it will be converted to gray or Y (of YCbCr) image according to the convert_to argument.

  • crop_border (int) – Cropped pixels in each edge of an image. These pixels are not involved in the metric calculation.

  • input_order (str) – Whether the input order is ‘HW’, ‘HWC’ or ‘CHW’. Default: ‘HWC’.

  • convert_to (str) – Whether converted to ‘y’ (of MATLAB YCbCr) or ‘gray’. Default: ‘y’.

Returns:

NIQE result.

Return type:

float

basicsr.metrics.niqe.compute_feature(block)[source]

Compute features.

Parameters:

block (ndarray) – 2D Image block.

Returns:

Features with length of 18.

Return type:

list

basicsr.metrics.niqe.estimate_aggd_param(block)[source]

Estimate AGGD (Asymmetric Generalized Gaussian Distribution) parameters.

Parameters:

block (ndarray) – 2D Image block.

Returns:

alpha (float), beta_l (float) and beta_r (float) for the AGGD

distribution (Estimating the parames in Equation 7 in the paper).

Return type:

tuple

basicsr.metrics.niqe.niqe(img, mu_pris_param, cov_pris_param, gaussian_window, block_size_h=96, block_size_w=96)[source]

Calculate NIQE (Natural Image Quality Evaluator) metric.

Paper: Making a "Completely Blind" Image Quality Analyzer

This implementation could produce almost the same results as the official MATLAB codes: http://live.ece.utexas.edu/research/quality/niqe_release.zip

Note that we do not include block overlap height and width, since they are always 0 in the official implementation.

For good performance, it is advisable by the official implementation to divide the distorted image in to the same size patched as used for the construction of multivariate Gaussian model.

Parameters:
  • img (ndarray) – Input image whose quality needs to be computed. The image must be a gray or Y (of YCbCr) image with shape (h, w). Range [0, 255] with float type.

  • mu_pris_param (ndarray) – Mean of a pre-defined multivariate Gaussian model calculated on the pristine dataset.

  • cov_pris_param (ndarray) – Covariance of a pre-defined multivariate Gaussian model calculated on the pristine dataset.

  • gaussian_window (ndarray) – A 7x7 Gaussian window used for smoothing the image.

  • block_size_h (int) – Height of the blocks in to which image is divided. Default: 96 (the official recommended value).

  • block_size_w (int) – Width of the blocks in to which image is divided. Default: 96 (the official recommended value).