前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OpenCV 实现SSIM结构相似性算法

OpenCV 实现SSIM结构相似性算法

作者头像
chaibubble
发布2018-01-02 10:01:30
3K0
发布2018-01-02 10:01:30
举报
文章被收录于专栏:深度学习与计算机视觉

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

代码语言:javascript
复制
#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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-04-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档