SSIM算法的介绍: http://blog.csdn.net/chaipp0607/article/details/70158835
代码做了一下处理: (1)设置两组对比试验,将原图进行核为5*5的滤波,与原图比较求得SSIM指数。将原图进行核为10*10的滤波,与原图比较求得SSIM指数。 (2)将SSIM指数折算为百分制 (3)采用高斯模糊求得图像的均值
代码参考: http://jingyan.baidu.com/article/456c463b67aa310a5931447a.html
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
Scalar getMSSIM(Mat inputimage1, Mat inputimage2);
int main()
{
Mat BlurImage1;
Mat BlurImage2;
Mat SrcImage = imread("1.jpg");
blur(SrcImage, BlurImage1, Size(5, 5));
blur(SrcImage,BlurImage2,Size(10,10));
Scalar SSIM1 = getMSSIM(SrcImage, BlurImage1);
Scalar SSIM2 = getMSSIM(SrcImage, BlurImage2);
printf("模糊5*5通道1:%f\n", SSIM1.val[0] * 100);
printf("模糊5*5通道2:%f\n", SSIM1.val[1] * 100);
printf("模糊5*5通道3:%f\n", SSIM1.val[2] * 100);
printf("模糊5*5:%f\n", (SSIM1.val[2] + SSIM1.val[1] + SSIM1.val[0])/3 * 100);
printf("模糊10*10通道1:%f\n", SSIM2.val[0] * 100);
printf("模糊10*10通道2:%f\n", SSIM2.val[1] * 100);
printf("模糊10*10通道3:%f\n", SSIM2.val[2] * 100);
printf("模糊10*10:%f\n", (SSIM2.val[2] + SSIM2.val[1] + SSIM2.val[0]) / 3 * 100);
imshow("原图",SrcImage);
imshow("模糊5*5",BlurImage1);
imshow("模糊10*10", BlurImage2);
waitKey(0);
return 0;
}
Scalar getMSSIM(Mat inputimage1, Mat inputimage2)
{
Mat i1 = inputimage1;
Mat i2 = inputimage2;
const double C1 = 6.5025, C2 = 58.5225;
int d = CV_32F;
Mat I1, I2;
i1.convertTo(I1, d);
i2.convertTo(I2, d);
Mat I2_2 = I2.mul(I2);
Mat I1_2 = I1.mul(I1);
Mat I1_I2 = I1.mul(I2);
Mat mu1, mu2;
GaussianBlur(I1, mu1, Size(11, 11), 1.5);
GaussianBlur(I2, mu2, Size(11, 11), 1.5);
Mat mu1_2 = mu1.mul(mu1);
Mat mu2_2 = mu2.mul(mu2);
Mat mu1_mu2 = mu1.mul(mu2);
Mat sigma1_2, sigma2_2, sigma12;
GaussianBlur(I1_2, sigma1_2, Size(11, 11), 1.5);
sigma1_2 -= mu1_2;
GaussianBlur(I2_2, sigma2_2, Size(11, 11), 1.5);
sigma2_2 -= mu2_2;
GaussianBlur(I1_I2, sigma12, Size(11, 11), 1.5);
sigma12 -= mu1_mu2;
Mat t1, t2, t3;
t1 = 2 * mu1_mu2 + C1;
t2 = 2 * sigma12 + C2;
t3 = t1.mul(t2);
t1 = mu1_2 + mu2_2 + C1;
t2 = sigma1_2 + sigma2_2 + C2;
t1 = t1.mul(t2);
Mat ssim_map;
divide(t3, t1, ssim_map);
Scalar mssim = mean(ssim_map);
return mssim;
}
打印结果: 模糊5*5通道1:82.523627 模糊5*5通道2:85.781376 模糊5*5通道3:85.903646 模糊5*5:84.736216 模糊10*10通道1:65.029142 模糊10*10通道2:69.286267 模糊10*10通道3:68.664205 模糊10*10:67.659871