Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

背景

from skimage.measure import compare_ssim, compare_psnr

をすると
compare_ssimcompare_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

img1 = cv2.imread("sample1.png", cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread("sample2.png", cv2.IMREAD_GRAYSCALE)
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倍ぐらい)

おまけ

画像間の同じ座標のピクセルと値との差の合計pixel_diffとの比較をしてみる。

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

img1 = cv2.imread("sample1.png", cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread("sample2.png", cv2.IMREAD_GRAYSCALE)
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]

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした