计算两幅图像的PSNR和SSIM的python源码
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]) ""