import os
import numpy as np
from scipy.misc import imread ,imresize
from PIL import Image
from skimage import color
from skimage.measure import compare_ssim, compare_psnr, compare_mse
from tqdm import tqdm
path1 = './A'
path2 = './B'
total_p = 0
total_s = 0
print('[***]calc...')
images = os.listdir(path1)
for image in tqdm(images):
# image pair have same size
img1 = imresize(imread(os.path.join(path1,image)),(576,720))
# print(type(img1)) = numpy.ndarray
img2 = imread(os.path.join(path2,'B'+image[1:]))
# 断言尺寸不同则抛出异常
assert img1.size == img2.size ,\
"image pair should have same size,check the img_size(w,h) "
err = img1 - img2
ie = np.mean(np.sqrt(np.sum(err * err, axis=2)))
psnr = compare_psnr(img1,img2)
ssim = compare_ssim(img1,img2,multichannel=1)
n = len(images)
# print(psnr,ssim)
total_p += psnr
total_s += ssim
mean_p = total_p/n
mean_s = total_s/n
print("avg_PSNR , avg_SSIM :","%.2f"% mean_p,",","%.3f"% mean_s)
print('Interpolation Error :',"%.2f"% ie)
遍历图像对计算psnr,ssim,IE
最新推荐文章于 2025-09-15 09:18:15 发布
本文介绍了一种使用Python进行图像相似度评估的方法,包括PSNR、SSIM等指标的计算,并展示了如何通过比较图像间的差异来量化图像质量。该方法适用于评估图像压缩效果、图像处理算法的性能以及图像识别系统的准确性。
1064

被折叠的 条评论
为什么被折叠?



