cutcutcodec.core.analysis.video.quality.ssim

cutcutcodec.core.analysis.video.quality.ssim(ref: Tensor, dis: Tensor, *args, stride: int = 1, **kwargs) Tensor[source]

Compute the Structural similarity index measure of 2 images.

Parameters

ref, disarraylike

The 2 images to be compared, of shape ([*batch], height, width, channels). Supported types are float32 and float64.

data_rangefloat, default=1.0

The data range of the input image (difference between maximum and minimum possible values).

weightsiterable[float], optional

The relative weight of each channel. By default, all channels have the same weight.

sigmafloat, default=1.5

The standard deviation of the gaussian. It has to be strictely positive.

strideint, default=1

The stride of the convolving kernel.

threadsint, optional

Defines the number of threads. The value -1 means that the function uses as many calculation threads as there are cores. The default value (0) allows the same behavior as (-1) if the function is called in the main thread, otherwise (1) to avoid nested threads. Any other positive value corresponds to the number of threads used.

Returns

ssimarraylike

The ponderated structural similarity index measure of each layers.

Notes

  • It is optimized for C contiguous tensors.

  • If device is cpu, gradient is not required and stride != 1, a fast C code is used.

Examples

>>> import numpy as np
>>> from cutcutcodec.core.analysis.video.quality import ssim
>>> np.random.seed(0)
>>> ref = np.random.random((720, 1080, 3))  # It could also be a torch array list...
>>> dis = 0.8 * ref + 0.2 * np.random.random((720, 1080, 3))
>>> ssim(ref, dis).round(2)
np.float64(0.95)
>>>