【代码实例】python和matlab计算出相同的PSNR,SSIM,MSE

之前做实验发现了一个问题,好像用python的skimage.metrics包计算PSNR等指标和matlab里面算出来的不太一样,当时全转成python算了,现在考虑到又有不同的对比实验啥的,打算统一一下python和matlab的指标计算:

代码

python版本:

from skimage.metrics import peak_signal_noise_ratio as psnr,structural_similarity as ssim,mean_squared_error as mse
from scipy.io import loadmat
import numpy as np
# 读取图片
x0 = loadmat('A.mat')["data"]
x2 = loadmat('AA.mat')["data"]
x0 = np.squeeze(x0)
x2 = np.squeeze(x2)

# 归一化
maxvalue1=x0.max()
minvalue1=x0.min()
x0 = (x0 - minvalue1) / (maxvalue1 - minvalue1)
maxvalue1=x2.max()
minvalue1=x2.min()
x2 = (x2 - minvalue1) / (maxvalue1 - minvalue1)

psnr0 = psnr(x0, x2, data_range=1)
ssim0 = ssim(x0,x2,gaussian_weights=True,  use_sample_covariance=False, data_range=1.0)
mse0 = mse(x0,x2)
print(psnr0)
print(ssim0)
print(mse0)

你可能感兴趣的:(学习笔记,效率,python,开发语言,matlab,图像处理)