图像评价标准:PSNR和SSIM

一、PSNR:峰值信噪比,公式如下:

图像评价标准:PSNR和SSIM_第1张图片

其中MSE是原图像和处理图像的均方误差,公式如下:

图像评价标准:PSNR和SSIM_第2张图片 

PSNR越大,表示两图相似度越高

实现代码如下:

import torch
import torch.nn.functional as F
from math import log10
import cv2
import numpy as np
import torchvision
from skimage.metrics import structural_similarity as ssim


def to_psnr(frame_out, gt):
    mse = F.mse_loss(frame_out, gt, reduction='none')
    mse_split = torch.split(mse, 1, dim=0)
    mse_list = [torch.mean(torch.squeeze(mse_split[ind])).item() for ind in range(len(mse_split))]
    intensity_max = 1.0
    psnr_list = [10.0 * log10(intensity_max / mse) for mse in mse_list]
    return psnr_list

 二、SSIM是一种结构性损失,通过衡量考察图与参考图在每个patch上的均值、标准差、协方差(以patch中心为中心的高斯窗加权求统计值)来衡量两张图的结构相似性。

skimage 代码实现:

def to_ssim_skimage(dehaze, gt):
    dehaze_list = torch.split(dehaze, 1, dim=0)
    gt_list = torch.split(gt, 1, dim=0)

    dehaze_list_np = [dehaze_list[ind].permute(0, 2, 3, 1).data.cpu().numpy().squeeze() for ind in
                      range(len(dehaze_list))]
    gt_list_np = [gt_list[ind].permute(0, 2, 3, 1).data.cpu().numpy().squeeze() for ind in range(len(dehaze_list))]
    ssim_list = [ssim(dehaze_list_np[ind], gt_list_np[ind], data_range=1, multichannel=True) for ind in
                 range(len(dehaze_list))]

    return ssim_list

你可能感兴趣的:(计算机视觉学习笔记,python,机器学习,深度学习)