博客
关于我
python SSIM and PSNR
阅读量:140 次
发布时间:2019-02-28

本文共 3377 字,大约阅读时间需要 11 分钟。

SSIM的输入就是两张图像,我们要得到其相似性的两张图像。其中一张是未经压缩的无失真图像(即ground truth),另一张就是你恢复出的图像。所以,SSIM可以作为super-resolution质量的指标。

  • SSIM input is two images, we want to get the similarity of the two images.One is an uncompressed, undistorted image (the ground truth), and the other is what you recover.Therefore, SSIM can be used as an indicator of super-resolution quality.

 SSIM具有对称性,即SSIM(x,y)=SSIM(y,x)SSIM是一个0到1之间的数,越大表示输出图像和无失真图像的差距越小,即图像质量越好。当两幅图像一模一样时,SSIM=1;

  • SSIM has symmetry, that is, SSIM(x,y)=SSIM(y,x)SSIM is a number between 0 and 1, the larger the difference between the output image and the undistorted image is, the better the image quality is.When two images are identical, SSIM=1;

计算PSNR要先知道MSE(均方误差)的计算。两个m×n单色图像I和K,如果一个为另外一个的噪声近似,那么它们的的均方误差定义为:

  • The CALCULATION of PSNR requires the calculation of MSE(mean square error).For two m× N monochromatic images I and K, if one is the noise approximation of the other, then their mean square error is defined as:

MSE的概念应该是比较熟悉的,这也是常见的损失函数。而PSNR就是通过MSE得出来的,公式如下:

  • The concept of MSE should be familiar, and this is a common loss function.PSNR is derived from MSE, and the formula is as follows:

其中,MAXI是表示图像点颜色的最大数值,如果每个采样点用 8 位表示,那么就是 255。所以MSE越小,则PSNR越大;所以PSNR越大,代表着图像质量越好。

  • Where, MAXI is the maximum value representing the color of the image points, which is 255 if each sampling point is represented by 8 bits.Therefore, the smaller the MSE, the larger the PSNR;So the bigger the PSNR, the better the image quality.

PSNR高于40dB说明图像质量极好(即非常接近原始图像),

在30—40dB通常表示图像质量是好的(即失真可以察觉但可以接受),

在20—30dB说明图像质量差;

最后,PSNR低于20dB图像不可接受

  • PSNR above 40dB indicates excellent image quality (i.e. very close to the original image),

  • Between 30 and 40dB usually means that the image quality is good (i.e., the distortion is detectable but acceptable),

  • Description of poor image quality at 20-30dB;

  • Finally, PSNR images below 20dB are not acceptable

import argparseimport osimport cv2import pandas as pdfrom skimage.measure import compare_ssimfrom skimage.measure import compare_psnrparser = argparse.ArgumentParser(description='image_eval')parser.add_argument('--orig_path',help='path to orig image dataset', default='orig/')parser.add_argument('--recon_path',help='path to recon image dataset', default='recon/')parser.add_argument('--image_format',help='format of the image', default='bmp')opt = parser.parse_args()num_files = 0for fn in os.listdir(opt.orig_path):    num_files += 1image_number = []psnr_number = []ssim_number = []for idx in range(num_files):    locals()['orig_'+str(idx)+''] = cv2.imread('%s/orig_%d.%s' %(opt.orig_path,idx,opt.image_format))    locals()['recon_'+str(idx)+''] = cv2.imread('%s/recon_%d.%s' %(opt.recon_path,idx,opt.image_format))    locals()['psnr_'+str(idx)+''] = compare_psnr(locals()['orig_'+str(idx)+''],locals()['recon_'+str(idx)+''])    locals()['ssim_'+str(idx)+''] = compare_ssim(locals()['orig_'+str(idx)+''],locals()['recon_'+str(idx)+''],multichannel=True)    image_number.append(str(idx))    psnr_number.append(locals()['psnr_'+str(idx)+''])    ssim_number.append(locals()['ssim_'+str(idx)+''])dit = {'image_number':image_number, 'psnr':psnr_number,'ssim':ssim_number}df = pd.DataFrame(dit)df.to_csv(r'./result.csv',columns=['image_number','psnr','ssim'],index=False,sep=',')

 I hope I can help you,If you have any questions, please  comment on this blog or send me a private message. I will reply in my free time.

转载地址:http://nngd.baihongyu.com/

你可能感兴趣的文章
MySql 手动执行主从备份
查看>>
Mysql 批量修改四种方式效率对比(一)
查看>>
mysql 批量插入
查看>>
Mysql 报错 Field 'id' doesn't have a default value
查看>>
MySQL 报错:Duplicate entry 'xxx' for key 'UNIQ_XXXX'
查看>>
Mysql 拼接多个字段作为查询条件查询方法
查看>>
mysql 排序id_mysql如何按特定id排序
查看>>
Mysql 提示:Communication link failure
查看>>
mysql 插入是否成功_PDO mysql:如何知道插入是否成功
查看>>
Mysql 数据库InnoDB存储引擎中主要组件的刷新清理条件:脏页、RedoLog重做日志、Insert Buffer或ChangeBuffer、Undo Log
查看>>
mysql 数据库中 count(*),count(1),count(列名)区别和效率问题
查看>>
mysql 数据库备份及ibdata1的瘦身
查看>>
MySQL 数据库备份种类以及常用备份工具汇总
查看>>
mysql 数据库存储引擎怎么选择?快来看看性能测试吧
查看>>
MySQL 数据库操作指南:学习如何使用 Python 进行增删改查操作
查看>>
MySQL 数据库的高可用性分析
查看>>
MySQL 数据库设计总结
查看>>
Mysql 数据库重置ID排序
查看>>
Mysql 数据类型一日期
查看>>
MySQL 数据类型和属性
查看>>