Shortcuts

NaturalImageQualityEvaluator

class mmeval.metrics.NaturalImageQualityEvaluator(crop_border: int = 0, input_order: str = 'CHW', convert_to: str = 'gray', channel_order: str = 'rgb', **kwargs)[源代码]

Calculate Natural Image Quality Evaluator(NIQE) 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

参数
  • crop_border (int) – Cropped pixels in each edges of an image. These pixels are not involved in the NIQE calculation. Defaults to 0.

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

  • convert_to (str) – Convert the images to other color models. Options are ‘y’ and ‘gray’. Defaults to ‘gray’.

  • channel_order (str) – The channel order of image. Defaults to ‘rgb’.

  • **kwargs – Keyword parameters passed to BaseMetric.

实际案例

>>> from mmeval import NaturalImageQualityEvaluator
>>> import numpy as np
>>>
>>> niqe = NaturalImageQualityEvaluator()
>>> preds = np.random.randint(0, 255, size=(3, 32, 32))
>>> niqe(preds)  
{'niqe': ...}
add(predictions: Sequence[numpy.ndarray], channel_order: Optional[str] = None)None[源代码]

Add NIQE score of batch to self._results

参数
  • predictions (Sequence[np.ndarray]) – Predictions of the model. Each prediction should be a 4D (as a video, not batches of images) or 3D (as an image) array.

  • channel_order (Optional[str]) – The channel order of the input samples. If not passed, will set as self.channel_order. Defaults to None.

compute_feature(block: numpy.ndarray)List[源代码]

Compute features.

参数

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

返回

Features with length of 18.

返回类型

List

compute_metric(results: List[numpy.float64])Dict[str, float][源代码]

Compute the NaturalImageQualityEvaluator metric.

This method would be invoked in BaseMetric.compute after distributed synchronization.

参数

results (List[np.float64]) – A list that consisting the NIQE score. This list has already been synced across all ranks.

返回

The computed NIQE metric.

返回类型

Dict[str, float]

compute_niqe(prediction: numpy.ndarray, channel_order: str, mu_pris_param: numpy.ndarray, cov_pris_param: numpy.ndarray, gaussian_window: numpy.ndarray, block_size_h: int = 96, block_size_w: int = 96)numpy.float64[源代码]

Calculate NIQE (Natural Image Quality Evaluator) metric. We use the official params estimated from the pristine dataset. We use the recommended block size (96, 96) without overlaps.

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 into the same size patched as used for the construction of multivariate Gaussian model.

参数
  • prediction (np.ndarray) – Input image whose quality to be computed. Range [0, 255] with float type.

  • channel_order (str) – The channel order of image.

  • 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. Defaults to 96.

  • block_size_w (int) – Width of the blocks in to which image is divided. Defaults to 96.

返回

NIQE result.

返回类型

np.float64

estimate_aggd_param(block: numpy.ndarray)Tuple[源代码]

Estimate AGGD (Asymmetric Generalized Gaussian Distribution) parameters.

参数

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

返回

alpha(float), beta_l(float) and beta_r(float) for the AGGD distribution (Estimating parameters in Equation 7 in the paper).

返回类型

Tuple

get_size_from_scale(input_size: Tuple, scale_factor: List[float])List[int][源代码]

Get the output size given input size and scale factor.

参数
  • input_size (Tuple) – The size of the input image.

  • scale_factor (List[float]) – The resize factor.

返回

The size of the output image.

返回类型

List[int]

get_weights_indices(input_length: int, output_length: int, scale: float, kernel: Callable, kernel_width: float)Tuple[List[numpy.ndarray], List[numpy.ndarray]][源代码]

Get weights and indices for interpolation.

参数
  • input_length (int) – Length of the input sequence.

  • output_length (int) – Length of the output sequence.

  • scale (float) – Scale factor.

  • kernel (Callable) – The kernel used for resizing.

  • kernel_width (float) – The width of the kernel.

返回

The weights and the indices for interpolation.

返回类型

Tuple[List[np.ndarray], List[np.ndarray]]

matlab_resize(img: numpy.ndarray, scale: float)numpy.ndarray[源代码]

Resize an image to the required size.

参数
  • img (np.ndarray) – The original image.

  • scale (float) – The scale factor of the resize operation.

返回

The resized image.

返回类型

np.ndarray

resize_along_dim(img_in: numpy.ndarray, weights: numpy.ndarray, indices: numpy.ndarray, dim: int)numpy.ndarray[源代码]

Resize along a specific dimension.

参数
  • img_in (np.ndarray) – The input image.

  • weights (np.ndarray) – The weights used for interpolation, computed from [get_weights_indices].

  • indices (np.ndarray) – The indices used for interpolation, computed from [get_weights_indices].

  • dim (int) – Which dimension to undergo interpolation.

返回

Interpolated (along one dimension) image.

返回类型

np.ndarray

Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.