ssim#

diffsptk.SSIM#

alias of StructuralSimilarityIndex

class diffsptk.StructuralSimilarityIndex(reduction='mean', *, alpha=1, beta=1, gamma=1, kernel_size=11, sigma=1.5, k1=0.01, k2=0.03, eps=1e-08, padding='same', dynamic_range=None)[source]#

Structural similarity index computation.

Parameters:
reduction[‘none’, ‘mean’, ‘sum’]

Reduction type.

alphafloat > 0

Relative importance of luminance component.

betafloat > 0

Relative importance of contrast component.

gammafloat > 0

Relative importance of structure component.

kernel_sizeint >= 1

Kernel size of Gaussian filter.

sigmafloat > 0

Standard deviation of Gaussian filter.

k1float > 0

A small constant.

k2float > 0

A small constant.

epsfloat >= 0

A small value to prevent NaN.

padding[‘valid’, ‘same’]

Padding type.

dynamic_rangefloat > 0 or None

Dynamic range of input. If None, input is automatically normalized.

References

[1] Z. Wang et al., “Image quality assessment: From error visibility to structural

similarity,” IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, 2004.

forward(x, y)[source]#

Calculate SSIM.

Parameters:
xTensor [shape=(…, N, D)]

Input.

yTensor [shape=(…, N, D)]

Target.

Returns:
outTensor [shape=(…, N, D) or scalar]

SSIM or mean SSIM.

Examples

>>> x = diffsptk.nrand(20, 20)
>>> y = diffsptk.nrand(20, 20)
>>> ssim = diffsptk.StructuralSimilarityIndex()
>>> s = ssim(x, y)
>>> s
tensor(0.0588)
diffsptk.functional.ssim(x, y, reduction='mean', *, alpha=1, beta=1, gamma=1, kernel_size=11, sigma=1.5, k1=0.01, k2=0.03, eps=1e-08, padding='same', dynamic_range=None)[source]#

Calculate SSIM.

Parameters:
xTensor [shape=(…, N, D)]

Input.

yTensor [shape=(…, N, D)]

Target.

reduction[‘none’, ‘mean’, ‘sum’]

Reduction type.

alphafloat > 0

Relative importance of luminance component.

betafloat > 0

Relative importance of contrast component.

gammafloat > 0

Relative importance of structure component.

kernel_sizeint >= 1

Kernel size of Gaussian filter.

sigmafloat > 0

Standard deviation of Gaussian filter.

k1float > 0

A small constant.

k2float > 0

A small constant.

epsfloat >= 0

A small value to prevent NaN.

padding[‘valid’, ‘same’]

Padding type.

dynamic_rangefloat > 0 or None

Dynamic range of input. If None, input is automatically normalized.

Returns:
outTensor [shape=(…, N, D) or scalar]

SSIM or mean SSIM.

See also

rmse