skimage2.metrics#

Warning

This module is part of the experimental skimage2 namespace and is subject to change without notice. Do not use it in production code. See the migration guide for more details.

Metrics corresponding to images, e.g., distance metrics, similarity, etc.

structural_similarity

Compute the mean structural similarity index between two images.


skimage2.metrics.structural_similarity(im1, im2, *, data_range, win_size=None, gradient=False, channel_axis=None, gaussian_weights=False, full=False, use_sample_covariance=True, K1=0.01, K2=0.03, sigma=1.5)[source]#

Compute the mean structural similarity index between two images.

Parameters:
im1, im2ndarray

Images. Any dimensionality with same shape.

data_rangefloat

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

win_sizeint or None, optional

The side-length of the sliding window used in comparisons (default: 7). Must be an odd value. If gaussian_weights is True, win_size cannot be specified since the window size is then determined by sigma.

gradientbool, optional

If True, also return the gradient with respect to im2.

channel_axisint or None, optional

If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.

gaussian_weightsbool, optional

If True, the local mean and variance are computed using a normalized Gaussian kernel of width sigma rather than a uniform window.

fullbool, optional

If True, also return the full structural similarity image.

use_sample_covariancebool, optional

If True, normalize covariances by N-1 rather than, N where N is the number of pixels within the sliding window.

K1float, optional

Algorithm parameter, K1 (small constant, see [1]).

K2float, optional

Algorithm parameter, K2 (small constant, see [1]).

sigmafloat, optional

Standard deviation for the Gaussian when gaussian_weights is True. Default is 1.5.

Returns:
mssimfloat

The mean structural similarity index over the image.

gradndarray

The gradient of the structural similarity between im1 and im2 [2]. This is only returned if gradient is set to True.

Sndarray

The full SSIM image. This is only returned if full is set to True.

Notes

To match the implementation of Wang et al. [1], set gaussian_weights to True, sigma to 1.5, use_sample_covariance to False, and specify the data_range argument.

References

[1] (1,2,3)

Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600-612. https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf, DOI:10.1109/TIP.2003.819861

[2]

Avanaki, A. N. (2009). Exact global histogram specification optimized for structural similarity. Optical Review, 16, 613-621. arXiv:0901.0065 DOI:10.1007/s10043-009-0119-z

Examples

>>> import skimage as ski
>>> import _skimage2 as ski2

Structural similarity between identical images is 1.0 >>> im1 = ski.data.camera() >>> structural_similarity(im1, im1.copy(), data_range=im1.max()) 1.0

Override part of the image with 0: >>> im2 = im1.copy() >>> im2[:30, :] = 0 >>> structural_similarity(im1, im2, data_range=im1.max()) # doctest: +ELLIPSIS 0.9408…