计算两张图像之间的PSNR和SSIM值

计算两张图像之间的PSNR和SSIM值

from skimage.metrics import mean_squared_error as mse
from skimage.metrics import peak_signal_noise_ratio as psnr
from skimage.metrics import structural_similarity as ssim
import cv2
import os
from glob import glob
from natsort import natsorted


target_dir = 'C:\LB\Restormer-masterpyV12/rain100L/test/norain'  # 标签图像(lable 、 ground-truth)存放路径
target_files = natsorted(glob(os.path.join(target_dir, '*.png')) + glob(os.path.join(target_dir, '*.jpg')))  # 标签图像(lable 、 ground-truth)名字的后缀

test_result_dir = 'C:\LB\Restormer-masterpyV12\YXL/result\LOL/rain100L'  # 预测图像(prediction、test、增强图像)存放路径
test_result_files = natsorted(glob(os.path.join(test_result_dir, '*.png')) + glob(os.path.join(test_result_dir, '*.jpg')))  # 预测图像(prediction、test、增强图像)名字的后缀


psnr_total = 0
ssim_total = 0
for i in range(0, len(target_files)):
    img1 = cv2.imread(target_files[i])
    img2 = cv2.imread(test_result_files[i])
    p = psnr(img1, img2)
    s = ssim(img1, img2, multichannel=True)  # 对于多通道图像(RGB、HSV等)关键词multichannel要设置为True
    print(p)
    # s = ssim(img1, img2)  # 对于多通道图像(RGB、HSV等)关键词multichannel要设置为True
    m = mse(img1, img2)

    psnr_total = p + psnr_total
    ssim_total = s + ssim_total

mean_psnr = psnr_total/len(target_files)
mean_ssim = ssim_total/len(target_files)
print('平均psnr的值为:',mean_psnr)
print('平均ssim的值为:',mean_ssim)

你可能感兴趣的:(深度学习之美,计算机视觉,python,opencv)