mse+psnr+ssim 批量

你说的曾经没有我的故事 提交于 2019-12-15 01:54:05
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()

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!