This is a development version (0.26.1rc0.dev0) and may be unstable.Go to latest (0.26.1rc0.dev0+git20260530.b607368ff)
{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0 / skimage / metrics / _structural_similarity / structural_similarity

function

skimage.metrics._structural_similarity:structural_similarity

source: /skimage/metrics/_structural_similarity.py:15

Signature

def structural_similarity(im1, im2, *, win_size = None, gradient = False, data_range = None, channel_axis = None, gaussian_weights = False, full = False, **kwargs)

Summary

Compute the mean structural similarity index between two images. Please pay attention to the data_range parameter with floating-point images.

Parameters

im1, im2 : ndarray

Images. Any dimensionality with same shape.

win_size : int 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 determined by sigma.

gradient : bool, optional

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

data_range : float, optional

The data range of the input image (difference between maximum and minimum possible values). By default, this is estimated from the image data type. This estimate may be wrong for floating-point image data. Therefore it is recommended to always pass this scalar value explicitly (see note below).

channel_axis : int 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_weights : bool, optional

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

full : bool, optional

If True, also return the full structural similarity image.

Returns

mssim : float

The mean structural similarity index over the image.

grad : ndarray

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

S : ndarray

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

Other Parameters

use_sample_covariance : bool

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

K1 : float

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

K2 : float

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

sigma : float

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

Notes

If data_range is not specified, the range is automatically guessed based on the image data type. However for floating-point image data, this estimate yields a result double the value of the desired range, as the dtype_range in skimage.util.dtype.py has defined intervals from -1 to +1. This yields an estimate of 2, instead of 1, which is most often required when working with image data (as negative light intensities are nonsensical). In case of working with YCbCr-like color data, note that these ranges are different per channel (Cb and Cr have double the range of Y), so one cannot calculate a channel-averaged SSIM with a single call to this function, as identical ranges are assumed for each channel.

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.

Aliases

  • skimage.metrics.structural_similarity