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)