pyiqa.archs.ssim_arch

SSIM, MS-SSIM, CW-SSIM Metric

Created by: - https://github.com/dingkeyan93/IQA-optimization/blob/master/IQA_pytorch/SSIM.py - https://github.com/dingkeyan93/IQA-optimization/blob/master/IQA_pytorch/MS_SSIM.py - https://github.com/dingkeyan93/IQA-optimization/blob/master/IQA_pytorch/CW_SSIM.py

Modified by: Jiadi Mo (https://github.com/JiadiMo)

Refer to:

https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/43017/versions/1/download/zip;

Module Contents

pyiqa.archs.ssim_arch.ssim(X, Y, win=None, get_ssim_map=False, get_cs=False, get_weight=False, downsample=False, data_range=1.0)[source]
class pyiqa.archs.ssim_arch.SSIM(channels=3, downsample=False, test_y_channel=True, color_space='yiq', crop_border=0.0)[source]

Bases: torch.nn.Module

Args: - channel: number of channel. - downsample: boolean, whether to downsample same as official matlab code. - test_y_channel: boolean, whether to use y channel on ycbcr same as official matlab code.

forward(X, Y)[source]
pyiqa.archs.ssim_arch.ms_ssim(X, Y, win=None, data_range=1.0, downsample=False, test_y_channel=True, is_prod=True, color_space='yiq')[source]

Compute Multiscale structural similarity for a batch of images. :param x: An input tensor. Shape \((N, C, H, W)\). :param y: A target tensor. Shape \((N, C, H, W)\). :param win: Window setting. :param downsample: Boolean, whether to downsample which mimics official SSIM matlab code. :param test_y_channel: Boolean, whether to use y channel on ycbcr. :param is_prod: Boolean, calculate product or sum between mcs and weight.

Returns:

Index of similarity between two images. Usually in [0, 1] interval.

class pyiqa.archs.ssim_arch.MS_SSIM(channels=3, downsample=False, test_y_channel=True, is_prod=True, color_space='yiq')[source]

Bases: torch.nn.Module

Multiscale structure similarity

References

Wang, Zhou, Eero P. Simoncelli, and Alan C. Bovik. “Multiscale structural similarity for image quality assessment.” In The Thrity-Seventh Asilomar Conference on Signals, Systems & Computers, 2003, vol. 2, pp. 1398-1402. Ieee, 2003.

Parameters:
  • channel – Number of channel.

  • downsample – Boolean, whether to downsample which mimics official SSIM matlab code.

  • test_y_channel – Boolean, whether to use y channel on ycbcr which mimics official matlab code.

forward(X, Y)[source]

Computation of MS-SSIM metric. :param x: An input tensor. Shape \((N, C, H, W)\). :param y: A target tensor. Shape \((N, C, H, W)\).

Returns:

Value of MS-SSIM metric in [0, 1] range.

class pyiqa.archs.ssim_arch.CW_SSIM(channels=1, level=4, ori=8, guardb=0, K=0, test_y_channel=True, color_space='yiq')[source]

Bases: torch.nn.Module

Complex-Wavelet Structural SIMilarity (CW-SSIM) index.

References

M. P. Sampat, Z. Wang, S. Gupta, A. C. Bovik, M. K. Markey. “Complex Wavelet Structural Similarity: A New Image Similarity Index”, IEEE Transactions on Image Processing, 18(11), 2385-401, 2009.

Parameters:
  • channel (-) – Number of channel.

  • test_y_channel (-) – Boolean, whether to use y channel on ycbcr.

  • level (-) – The number of levels to used in the complex steerable pyramid decomposition

  • ori (-) – The number of orientations to be used in the complex steerable pyramid decomposition

  • guardb (-) – How much is discarded from the four image boundaries.

  • K (-) – the constant in the CWSSIM index formula (see the above reference) default value: K=0

conj(x, y)[source]
conv2d_complex(x, win, groups=1)[source]
cw_ssim(x, y, test_y_channel)[source]

Compute CW-SSIM for a batch of images. :param x: An input tensor. Shape \((N, C, H, W)\). :param y: A target tensor. Shape \((N, C, H, W)\). :param test_y_channel: Boolean, whether to use y channel on ycbcr.

Returns:

Index of similarity between two images. Usually in [0, 1] interval.

forward(X, Y)[source]

Computation of CW-SSIM metric. :param X: An input tensor. Shape \((N, C, H, W)\). :param Y: A target tensor. Shape \((N, C, H, W)\).

Returns:

Value of CW-SSIM metric in [0, 1] range.