Shortcuts

mmedit.evaluation.metrics.niqe

Module Contents

Classes

NIQE

Calculate NIQE (Natural Image Quality Evaluator) metric.

Functions

estimate_aggd_param(block)

Estimate AGGD (Asymmetric Generalized Gaussian Distribution) parameters.

compute_feature(block)

Compute features.

niqe_core(img, mu_pris_param, cov_pris_param, ...[, ...])

Calculate NIQE (Natural Image Quality Evaluator) metric.

niqe(img, crop_border[, input_order, convert_to])

Calculate NIQE (Natural Image Quality Evaluator) metric.

class mmedit.evaluation.metrics.niqe.NIQE(key: str = 'pred_img', is_predicted: bool = True, collect_device: str = 'cpu', prefix: Optional[str] = None, crop_border=0, input_order='HWC', convert_to='gray')[source]

Bases: mmedit.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric

Calculate NIQE (Natural Image Quality Evaluator) metric.

Ref: 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

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

Parameters
  • key (str) – Key of image. Default: ‘pred_img’

  • is_predicted (bool) – If the image is predicted, it will be picked from predictions; otherwise, it will be picked from data_batch. Default: True

  • collect_device (str) – Device name used for collecting results from different ranks during distributed training. Must be ‘cpu’ or ‘gpu’. Defaults to ‘cpu’.

  • prefix (str, optional) – The prefix that will be added in the metric names to disambiguate homonymous metrics of different evaluators. If prefix is not provided in the argument, self.default_prefix will be used instead. Default: None

  • crop_border (int) – Cropped pixels in each edges of an image. These pixels are not involved in the PSNR calculation. Default: 0.

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

  • convert_to (str) – Whether to convert the images to other color models. If None, the images are not altered. When computing for ‘Y’, the images are assumed to be in BGR order. Options are ‘Y’ and None. Default: ‘gray’.

Metrics:
  • NIQE (float): Natural Image Quality Evaluator

metric = NIQE[source]
process_image(gt, pred, mask) None[source]

Process an image.

Parameters
  • gt (np.ndarray) – GT image.

  • pred (np.ndarray) – Pred image.

  • mask (np.ndarray) – Mask of evaluation.

Returns

NIQE result.

Return type

result (np.ndarray)

mmedit.evaluation.metrics.niqe.estimate_aggd_param(block)[source]

Estimate AGGD (Asymmetric Generalized Gaussian Distribution) parameters.

Parameters

block (np.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

mmedit.evaluation.metrics.niqe.compute_feature(block)[source]

Compute features.

Parameters

block (np.ndarray) – 2D Image block.

Returns

Features with length of 18.

Return type

feat (List)

mmedit.evaluation.metrics.niqe.niqe_core(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.

Ref: 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 (np.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 (np.ndarray) – Mean of a pre-defined multivariate Gaussian model calculated on the pristine dataset.

  • cov_pris_param (np.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). Default: 96.

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

Returns

NIQE quality.

Return type

np.ndarray

mmedit.evaluation.metrics.niqe.niqe(img, crop_border, input_order='HWC', convert_to='y')[source]

Calculate NIQE (Natural Image Quality Evaluator) metric.

Ref: 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

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

Parameters
  • img (np.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

niqe_result (float)

Read the Docs v: latest
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.