NaturalImageQualityEvaluator¶
- class mmeval.metrics.NaturalImageQualityEvaluator(crop_border: int = 0, input_order: str = 'CHW', convert_to: str = 'gray', channel_order: str = 'rgb', **kwargs)[source]¶
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
- Parameters
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
.
Examples
>>> 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[source]¶
Add NIQE score of batch to
self._results
- Parameters
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[source]¶
Compute features.
- Parameters
block (np.ndarray) – 2D Image block.
- Returns
Features with length of 18.
- Return type
List
- compute_metric(results: List[numpy.float64]) → Dict[str, float][source]¶
Compute the NaturalImageQualityEvaluator metric.
This method would be invoked in
BaseMetric.compute
after distributed synchronization.- Parameters
results (List[np.float64]) – A list that consisting the NIQE score. This list has already been synced across all ranks.
- Returns
The computed NIQE metric.
- Return type
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[source]¶
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.
- Parameters
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.
- Returns
NIQE result.
- Return type
np.float64
- estimate_aggd_param(block: numpy.ndarray) → Tuple[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 parameters in Equation 7 in the paper).
- Return type
Tuple
- get_size_from_scale(input_size: Tuple, scale_factor: List[float]) → List[int][source]¶
Get the output size given input size and scale factor.
- Parameters
input_size (Tuple) – The size of the input image.
scale_factor (List[float]) – The resize factor.
- Returns
The size of the output image.
- Return type
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]][source]¶
Get weights and indices for interpolation.
- Parameters
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.
- Returns
The weights and the indices for interpolation.
- Return type
Tuple[List[np.ndarray], List[np.ndarray]]
- matlab_resize(img: numpy.ndarray, scale: float) → numpy.ndarray[source]¶
Resize an image to the required size.
- Parameters
img (np.ndarray) – The original image.
scale (float) – The scale factor of the resize operation.
- Returns
The resized image.
- Return type
np.ndarray
- resize_along_dim(img_in: numpy.ndarray, weights: numpy.ndarray, indices: numpy.ndarray, dim: int) → numpy.ndarray[source]¶
Resize along a specific dimension.
- Parameters
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.
- Returns
Interpolated (along one dimension) image.
- Return type
np.ndarray