mu2

计算两幅图像的PSNR和SSIM的python源码

老子叫甜甜 提交于 2020-03-02 18:44:57
import math import numpy as np from skimage import io from scipy . signal import convolve2d def compute_psnr ( img1 , img2 ) : if isinstance ( img1 , str ) : img1 = io . imread ( img1 ) if isinstance ( img2 , str ) : img2 = io . imread ( img2 ) mse = np . mean ( ( img1 / 255 . - img2 / 255 . ) ** 2 ) if mse < 1.0e-10 : return 1000000000000 PIXEL_MAX = 1 psnr = 20 * math . log10 ( PIXEL_MAX / math . sqrt ( mse ) ) return mse , psnr def matlab_style_gauss2D ( shape = ( 3 , 3 ) , sigma = 0.5 ) : """ 2D gaussian mask - should give the same result as MATLAB's fspecial('gaussian',[shape],[sigma]) ""

OpenCV的视频输入和相似度测量

允我心安 提交于 2019-11-26 14:22:23
#include <iostream> #include <string> #include <iomanip> // 控制浮动类型的打印精度 #include <sstream> // 字符串和数值的转换 #include <opencv2/core.hpp> // CV::Mat,Scalar #include <opencv2/imgproc.hpp> // 高斯平滑 #include <opencv2/videoio.hpp> // 视频 #include <opencv2/highgui.hpp> using namespace std; using namespace cv; double getPSNR(const Mat& I1, const Mat& I2); Scalar getMSSIM(const Mat& I1, const Mat& I2); int main(int argc, char *argv[]) { const string sourceReference = "E:\\VS2015Opencv\\vs2015\\project\\video\\01.avi"; const string sourceCompareWith = "E:\\VS2015Opencv\\vs2015\\project\\video\\011.avi"; int