viqa.fr_metrics.ssim.structural_similarity¶
- viqa.fr_metrics.ssim.structural_similarity(img_r, img_m, win_size=None, data_range=None, gaussian_weights=True, alpha=1, beta=1, gamma=1, **kwargs)[source]¶
Compute the structural similarity index between two images.
- Parameters:
img_r (np.ndarray) – Reference image to calculate score against.
img_m (np.ndarray) – Modified image to calculate score of.
win_size (int or None, optional) – The side-length of the sliding window used in comparison. Must be an odd value. If
gaussian_weights
is True, this is ignored and the window size will depend onsigma
.data_range (int, default=None) – Data range of the input images.
gaussian_weights (bool, default=True) – If True, each patch has its mean and variance spatially weighted by a normalized Gaussian kernel of width sigma=1.5.
alpha (float, default=1) – Weight of the luminance comparison. Should be alpha >=1.
beta (float, default=1) – Weight of the contrast comparison. Should be beta >=1.
gamma (float, default=1) – Weight of the structure comparison. Should be gamma >=1.
K1 (float, default=0.01) – Algorithm parameter, K1 (small constant, see [1]).
K2 (float, default=0.03) – Algorithm parameter, K2 (small constant, see [1]).
sigma (float, default=1.5) – Standard deviation for the Gaussian when
gaussian_weights
is True.mode (str, default='reflect') –
Determines how the array borders are handled. ‘constant’, ‘edge’, ‘symmetric’, ‘reflect’ or ‘wrap’.
See also
See Scipy documentation for
scipy.ndimage.gaussian_filter()
orscipy.ndimage.uniform_filter()
for more information on the modes.cval (float, optional) – Value to fill past edges of input if
mode
is ‘constant’. Default is 0.
- Returns:
ssim – The mean structural similarity index over the image.
- Return type:
float
- Raises:
ValueError – If
K1
,K2
orsigma
are negative. Ifwin_size
exceeds image or is not an odd number.- Warns:
RuntimeWarning – If
alpha
,beta
orgamma
are not integers.
Notes
To match the implementation in [1], set
gaussian_weights
to True andsigma
to 1.5. This code is adapted fromskimage.metrics.structural_similarity()
available under [2]. The metric would possibly result in a value of nan in specific cases. To avoid this, the function replaces nan values with 1.0 before computing the final score.References