# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# ssim

Structural Similarity Index (SSIM) for measuring image quality

## Syntax

• ``ssimval = ssim(A,ref)``
• ``````[ssimval,ssimmap] = ssim(A,ref)``````
example
• ``___ = ssim(__,Name,Value,...)``

## Description

````ssimval = ssim(A,ref)` computes the Structural Similarity Index (SSIM) value for image `A` using `ref` as the reference image. ```

example

``````[ssimval,ssimmap] = ssim(A,ref)``` returns the local SSIM value for each pixel in `A`. ```
````___ = ssim(__,Name,Value,...)` computes the SSIM, using name-value pairs to control aspects of the computation. Parameter names can be abbreviated.```

## Examples

collapse all

Read an image into the workspace. Create another version of the image, applying a blurring filter. Display both images.

```ref = imread('pout.tif'); H = fspecial('Gaussian',[11 11],1.5); A = imfilter(ref,H,'replicate'); subplot(1,2,1); imshow(ref); title('Reference Image'); subplot(1,2,2); imshow(A); title('Blurred Image'); ```

Calculate the global SSIM value for the image and local SSIM values for each pixel. Return the global SSIM value and display the local SSIM value map.

```[ssimval, ssimmap] = ssim(A,ref); fprintf('The SSIM value is %0.4f.\n',ssimval); figure, imshow(ssimmap,[]); title(sprintf('ssim Index Map - Mean ssim Value is %0.4f',ssimval)); ```
```The SSIM value is 0.9407. ```

## Input Arguments

collapse all

Image whose quality is to be measured, specified as a 2-D grayscale image or 3-D volume image. Must be the same size and class as `ref`

Data Types: `single` | `double` | `int16` | `uint8` | `uint16`

Reference image against which quality if measured, specified as a 2-D grayscale image or 3-D volume image. Must be the same size and class as `A`

Data Types: `single` | `double` | `int16` | `uint8` | `uint16`

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside single quotes (`' '`). You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example:

collapse all

Dynamic range of the input image, specified as a positive scalar. By default, this value is chosen based on the class of the input image `A`, as `diff(getrangefromclass(A))`. When class of `A` is `single` or `double`, this value is `1`, by default.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32`

Exponents for the luminance, contrast, and structural terms, specified as a three-element vector of nonnegative real numbers, ```[alpha beta gamma]```.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32`

Standard deviation of isotropic Gaussian function, specified as a positive scalar. This value is used for weighting the neighborhood pixels around a pixel for estimating local statistics. This weighting is used to avoid blocking artifacts in estimating local statistics.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32`

Regularization constants for the luminance, contrast, and structural terms, specified as a three-element vector of nonnegative real numbers. `ssim` uses these regularization constants to avoid instability for image regions where the local mean or standard deviation is close to zero. Therefore, small non-zero values should be used for these constants.

By default,

• `C1 = (0.01*L).^2`, where `L` is the specified `DynamicRange` value.

• `C2 = (0.03*L).^2`, where `L` is the specified `DynamicRange` value.

• `C3 = C2/2`

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32`

## Output Arguments

collapse all

Structural Similarity (SSIM) Index, returned as a scalar `double`, except when `A` and `ref` are of class `single`, in which case `ssimval` is of class `single`.

Local values of Structural Similarity (SSIM) Index, returned as a numeric array of class `double` except when `A` and `ref` are of class `single`, in which case `ssimmap` is of class `single`. `ssimmap` is an array of the same size as input image `A`.

collapse all

### Structural Similarity Index

An image quality metric that assesses the visual impact of three characteristics of an image: luminance, contrast and structure.

### Algorithms

The Structural Similarity (SSIM) Index quality assessment index is based on the computation of three terms, namely the luminance term, the contrast term and the structural term. The overall index is a multiplicative combination of the three terms.

`$SSIM\left(x,y\right)={\left[l\left(x,y\right)\right]}^{\alpha }\cdot {\left[c\left(x,y\right)\right]}^{\beta }\cdot {\left[s\left(x,y\right)\right]}^{\gamma }$`

where

`$\begin{array}{l}l\left(x,y\right)=\frac{2{\mu }_{x}{\mu }_{y}+{C}_{1}}{{\mu }_{x}^{2}+{\mu }_{y}^{2}+{C}_{1}},\\ c\left(x,y\right)=\frac{2{\sigma }_{x}{\sigma }_{y}+{C}_{2}}{{\sigma }_{x}^{2}+{\sigma }_{y}^{2}+{C}_{2}},\\ s\left(x,y\right)=\frac{{\sigma }_{xy}+{C}_{3}}{{\sigma }_{x}{\sigma }_{y}+{C}_{3}}\end{array}$`

where μx, μy, σxy, and σxy are the local means, standard deviations, and cross-covariance for images x, y. If α = β = γ = 1 (the default for Exponents), and C3 = C2/2 (default selection of C3) the index simplifies to:

`$SSIM\left(x,y\right)=\frac{\left(2{\mu }_{x}{\mu }_{y}+{C}_{1}\right)\left(2{\sigma }_{xy}+{C}_{2}\right)}{\left({\mu }_{x}^{2}+{\mu }_{y}^{2}+{C}_{1}\right)\left({\sigma }_{x}^{2}+{\sigma }_{y}^{2}+{C}_{2}\right)}$`

## References

[1] Wang Zhou, Bovik, Alan C., Sheikh, Hamid R., and Simoncelli, Eero P.Image Qualifty Assessment: From Error Visibility to Structural Similarity. IEEE Transactions on Image Processing, Volume 13, Issue 4, pp. 600–612, April 2004