最近用ssim测试图片画质损伤时,发现matlab自带ssim与以前一直使用的ssim计算得分有差别,故和同事开始肯定差别所在。
app
这里提到不一样的ssim版本主要基于matlab。如前言所述,主要分为2个实现。测试
虽然2个版本的代码实现彻底不同,但总的说,差别能够归结为如下几点:3d
The precisely right scale depends on both the image resolution and the viewing distance and is usually difficult to be obtained. In practice, we suggest to use the following empirical formula to determine the scale for images viewed from a typical distance (say 3~5 times of the image height or width): 1) Let F = max(1, round(N/256)), where N is the number of pixels in image height (or width); 2) Average local F by F pixels and then downsample the image by a factor of F; and 3) apply the ssim_index.m program. For example, for an 512 by 512 image, F = max(1, round(512/256)) = 2, so the image should be averaged within a 2 by 2 window and downsampled by a factor of 2 before applying ssim_index.m.
code
上面这段意思:人看图片时,与图片有必定距离(至关于图片缩小),一些细节可被忽略,若是进行downsample,除了减低运算复杂度,还能更贴合人的主观观看感觉。
orm
涉及downsample的代码部分:blog
% automatic downsampling f = max(1,round(min(M,N)/256)); %downsampling by f %use a simple low-pass filter if(f>1) lpf = ones(f,f); lpf = lpf/sum(lpf(:)); img1 = imfilter(img1,lpf,'symmetric','same'); img2 = imfilter(img2,lpf,'symmetric','same'); img1 = img1(1:f:end,1:f:end); img2 = img2(1:f:end,1:f:end); end
Zhou Wang版本
代码:图片
window = fspecial('gaussian', 11, 1.5); % 算子类型:gaussian(高斯) % 模版尺寸:11*11 % 标准差:1.5 % 以上参数皆hardcode
matlab版本
代码:ci
filtRadius = ceil(radius*3); filtSize = 2*filtRadius + 1; if (N < 3) gaussFilt = fspecial('gaussian',[filtSize filtSize],radius); % 2D mask else ...% 3D mask end % 算子类型:gaussian(高斯) % 模版尺寸:[filtSize filtSize],使用默认值计算后,为:11*11矩阵; % 标准差:radius,默认值为:1.5; % 以上参数皆可经过传参改变