This example shows how to compute the SSIM
value for a blurred image given the original image as a reference
image.

Read an image and blur it. 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));

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.

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

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

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.

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.

where

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

[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