python計算PSNR

 將兩張圖都轉成float64進行計算,且歸一化到0~1,防止精度丟失

import numpy as np

def getpsnr(img1,bitdepth1,img2,bitdepth2):
    img1 = np.float64(img1) / (2**bitdepth1-1)
    img2 = np.float64(img2) / (2**bitdepth2-1)
    mse = np.mean(np.square(img1-img2))
    psnr = - 10 * np.log10(mse)
    return psnr

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章