basicsr.metrics.psnr_ssim

basicsr.metrics.psnr_ssim.calculate_psnr(img, img2, crop_border, input_order='HWC', test_y_channel=False, **kwargs)[source]

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

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

Parameters:
  • img (ndarray) – Images with range [0, 255].

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

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

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

  • test_y_channel (bool) – Test on Y channel of YCbCr. Default: False.

Returns:

PSNR result.

Return type:

float

basicsr.metrics.psnr_ssim.calculate_psnr_pt(img, img2, crop_border, test_y_channel=False, **kwargs)[source]

Calculate PSNR (Peak Signal-to-Noise Ratio) (PyTorch version).

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

Parameters:
  • img (Tensor) – Images with range [0, 1], shape (n, 3/1, h, w).

  • img2 (Tensor) – Images with range [0, 1], shape (n, 3/1, h, w).

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

  • test_y_channel (bool) – Test on Y channel of YCbCr. Default: False.

Returns:

PSNR result.

Return type:

float

basicsr.metrics.psnr_ssim.calculate_ssim(img, img2, crop_border, input_order='HWC', test_y_channel=False, **kwargs)[source]

Calculate SSIM (structural similarity).

Paper: Image quality assessment: From error visibility to structural similarity

The results are the same as that of the official released MATLAB code in https://ece.uwaterloo.ca/~z70wang/research/ssim/.

For three-channel images, SSIM is calculated for each channel and then averaged.

Parameters:
  • img (ndarray) – Images with range [0, 255].

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

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

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

  • test_y_channel (bool) – Test on Y channel of YCbCr. Default: False.

Returns:

SSIM result.

Return type:

float

basicsr.metrics.psnr_ssim.calculate_ssim_pt(img, img2, crop_border, test_y_channel=False, **kwargs)[source]

Calculate SSIM (structural similarity) (PyTorch version).

Paper: Image quality assessment: From error visibility to structural similarity

The results are the same as that of the official released MATLAB code in https://ece.uwaterloo.ca/~z70wang/research/ssim/.

For three-channel images, SSIM is calculated for each channel and then averaged.

Parameters:
  • img (Tensor) – Images with range [0, 1], shape (n, 3/1, h, w).

  • img2 (Tensor) – Images with range [0, 1], shape (n, 3/1, h, w).

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

  • test_y_channel (bool) – Test on Y channel of YCbCr. Default: False.

Returns:

SSIM result.

Return type:

float