Shortcuts

PeakSignalNoiseRatio

class mmeval.metrics.PeakSignalNoiseRatio(crop_border: int = 0, input_order: str = 'CHW', convert_to: Optional[str] = None, channel_order: str = 'rgb', **kwargs)[source]

Peak Signal-to-Noise Ratio.

Ref: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

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

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

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

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

  • **kwargs – Keyword parameters passed to BaseMetric.

Examples

>>> from mmeval import PeakSignalNoiseRatio as PSNR
>>> import numpy as np
>>>
>>> psnr = PSNR(input_order='CHW', convert_to='Y', channel_order='rgb')
>>> gts = np.random.randint(0, 255, size=(3, 32, 32))
>>> preds = np.random.randint(0, 255, size=(3, 32, 32))
>>> psnr(preds, gts)  
{'psnr': ...}

Calculate PeakSignalNoiseRatio between 2 single channel images:

>>> img1 = np.ones((32, 32))
>>> img2 = np.ones((32, 32))
>>> PSNR.compute_psnr(img1, img2)
49.45272242415597
add(predictions: Sequence[numpy.ndarray], groundtruths: Sequence[numpy.ndarray], channel_order: Optional[str] = None)None[source]

Add PeakSignalNoiseRatio score of batch to self._results

Parameters
  • predictions (Sequence[np.ndarray]) – Predictions of the model.

  • groundtruths (Sequence[np.ndarray]) – The ground truth images.

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

compute_metric(results: List[numpy.float64])Dict[str, float][source]

Compute the PeakSignalNoiseRatio metric.

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

Parameters

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

Returns

The computed PeakSignalNoiseRatio metric.

Return type

Dict[str, float]

static compute_psnr(prediction: numpy.ndarray, groundtruth: numpy.ndarray)numpy.float64[source]

Calculate PeakSignalNoiseRatio (Peak Signal-to-Noise Ratio).

Ref: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

Parameters
  • prediction (np.ndarray) – Images with range [0, 255].

  • groundtruth (np.ndarray) – Images with range [0, 255].

Returns

PeakSignalNoiseRatio result.

Return type

np.float64

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.