14

More than 5 years have passed since last update.

# 画像品質評価のPSNR, SSIMの実装と速度比較

Last updated at Posted at 2018-09-26

# 背景

``````from skimage.measure import compare_ssim, compare_psnr
``````

をすると
`compare_ssim``compare_psnr`でSSIMとPSNRの評価ができる。

# 速度比較

``````from skimage.measure import compare_ssim, compare_psnr
import cv2
import time

def measurement(func, **kwargs):
start = time.time()
val = func(kwargs["img1"], kwargs["img2"])
end = time.time()
return val, end-start

print("ssim: %f, time: %lf[sec]" % measurement(compare_ssim, img1=img1, img2=img2))
print("psnr: %f, time: %lf[sec]" % measurement(compare_psnr, img1=img1, img2=img2))

# => ssim: 0.974289, time: 0.806180[sec]
# => psnr: 21.250949, time: 0.053643[sec]
``````

# 結論

わかってはいたけどPSNRの方がめっちゃ早い。(15倍ぐらい)

# おまけ

``````from skimage.measure import compare_ssim, compare_psnr
import cv2
import time
import numpy as np

def pixel_diff(img1, img2):
return np.sum(np.absolute(img1 - img2))

def measurement(func, **kwargs):
start = time.time()
val = func(kwargs["img1"], kwargs["img2"])
end = time.time()
return val, end-start

print("ssim: %f, time: %lf[sec]" % measurement(compare_ssim, img1=img1, img2=img2))
print("psnr: %f, time: %lf[sec]" % measurement(compare_psnr, img1=img1, img2=img2))
print("pixel_diff: %f, time: %lf[sec]" % measurement(compare_psnr, img1=img1, img2=img2))

# => ssim: 0.996097, time: 0.734509[sec]
# => psnr: 29.721666, time: 0.046622[sec]
# => pixel_diff: 29.721666, time: 0.045121[sec]
``````

# 参考

Register as a new user and use Qiita more conveniently

1. You get articles that match your needs
2. You can efficiently read back useful information
3. You can use dark theme
What you can do with signing up
14