python计算psnr

  • Post author:
  • Post category:python


import numpy as np
import math

def cal_psnr():
    quant_output = np.fromfile("./output/output.raw", dtype='uint16')
    quant_output = quant_output.astype('float64')

    compiled_output = np.fromfile("./output_mc50/dump_ocm_hsk_output_nhwc.raw", dtype='uint16')
    compiled_output = compiled_output.astype('float64')

    diff = quant_output - compiled_output
    rmse = math.sqrt(np.mean(diff ** 2.))
    eps = np.finfo(np.float64).eps
    if(rmse == 0):
        rmse = eps
    else:
    	# 65535 = 2^16-1, because original data type is uint16 
        rmse = 20*math.log10(65535.0/rmse)
    print(f"psnr = {rmse}")

if __name__ == "__main__":
    cal_psnr()



版权声明:本文为YoungHong1992原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。