from skimage.measure import compare_ssim, compare_mse, compare_psnr
import cv2
import os
import numpy as np
cnt=0
HD_path=r"C:\Users\Song\Desktop\test\HD"
LC_path=r"C:\Users\Song\Desktop\test\LC"
HD_files = os.listdir(HD_path)
for HD_file in HD_files:
cnt+=1
print(cnt)
i=1
mse =np.empty(cnt)
psnr=np.empty(cnt)
ssim=np.empty(cnt)
while(i<=cnt):
img1=cv2.imread(os.path.join(HD_path,"%d.png"%i))#图片从1.png开始
img2=cv2.imread(os.path.join(LC_path,"%d.png"%i))
j=i-1#数组下标从0开始
mse[j] = compare_mse(img1,img2)
ssim[j] = compare_ssim(img1, img2, data_range=255,multichannel=True)
psnr[j] = compare_psnr(img1,img2)
print ('%d.png'%i + 'mse :' + str(mse[j]))
print ('%d.png'%i + 'psnr :' + str(psnr[j]))
print ('%d.png'%i + 'ssim :' + str(ssim[j]))
i=i+1
avg_mse = np.sum(mse)/cnt
avg_psnr = np.sum(psnr)/cnt
avg_ssim = np.sum(ssim)/cnt
print('svg_mse' + str(avg_mse))
print('svg_psnr' + str(avg_psnr))
print('avg_ssim' + str(avg_ssim))
save_path = r'C:\Users\Song\Desktop\test\mps.txt'
with open (save_path,'w') as f:
for j in range(cnt):
f.write('%d.png'%(j+1) + 'mse :' + str(mse[j])+'\n')
f.write('%d.png'%(j+1) + 'psnr :' + str(psnr[j])+'\n')
f.write('%d.png'%(j+1) + 'ssim :' + str(ssim[j])+'\n')
f.write('svg_mse :' + str(avg_mse)+'\n')
f.write('svg_psnr :' + str(avg_psnr)+'\n')
f.write('svg_ssim :' + str(avg_ssim)+'\n')
f.close()
来源:CSDN
作者:今天依旧是小白
链接:https://blog.csdn.net/weixin_40632944/article/details/103473933