www.gusucode.com > images 案例代码 matlab源码程序 > images/CalculateStructuralSimilarityIndexSSIMExample.m

    %% Calculate Structural Similarity Index (SSIM)
% 
%%
% 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));