文章目录
图像质量评价指标
记噪声图为 X X X,滤波后的图像为 F F F,标准图像为 O O O。 M , N M,N M,N为图像的两个维度的大小。
Peak Signal to Noise Ratio (PSNR)
峰值信噪比。
如果图像是8位灰度图像,则:
P S N R = 10 ⋅ log ( 25 5 2 M S E ) \mathrm{PSNR}=10 \cdot \log \left(\frac{255^{2}}{\mathrm{MSE}}\right) PSNR=10⋅log(MSE2552)
其中: M S E \mathrm{MSE} MSE为均方误差
M S E = 1 M × N ∑ i = 0 M − 1 ∑ j = 0 N − 1 [ O ( i , j ) − F ( i , j ) ] 2 \mathrm{MSE}=\frac{1}{M \times N} \sum_{i=0}^{M-1} \sum_{j=0}^{N-1}[O(i, j)-F(i, j)]^{2} MSE=M×N1i=0∑M−1j=0∑N−1[O(i,j)−F(i,j)]2
PSNR值越大,图像质量越高。
Structural Similarity Index Metric(SSIM)
结构相似性。
SSIM ( O , F ) = ( 2 μ O μ F + c 1 ) ( 2 σ O F + c 2 ) ( μ O 2 + μ F 2 + c 1 ) ( σ O 2 + σ F 2 + c 2 ) \operatorname{SSIM}(O, F)=\frac{\left(2 \mu_{O} \mu_{F}+c_{1}\right)\left(2 \sigma_{O F}+c_{2}\right)}{\left(\mu_{O}^{2}+\mu_{F}^{2}+c_{1}\right)\left(\sigma_{O}^{2}+\sigma_{F}^{2}+c_{2}\right)} SSIM(O,F)=(μO2+μF2+c1)(σO2+σF2+c2)(2μOμF+c1)(2σOF+c2)
其中 μ O , μ F , σ O 2 , σ F 2 \mu_O,\mu_F,\sigma^2_O,\sigma^2_F μO,μF,σO2,σF2和 σ O F \sigma_{OF} σOF分别是图像 O O O和 F F F的平均强度、标准差和协方差。
μ 0 = 1 M × N ∑ i = 0 M − 1 ∑ j = 0 N − 1 O ( i , j ) , μ F = 1 M × N ∑ i = 0 M − 1 ∑ j = 0 N − 1 F ( i , j ) \mu_{0}=\frac{1}{M \times N} \sum_{i=0}^{M-1} \sum_{j=0}^{N-1} O(i, j), \quad \mu_{F}=\frac{1}{M \times N} \sum_{i=0}^{M-1} \sum_{j=0}^{N-1} F(i, j) μ0=M×N1i=0∑M−1j=0∑N−1O(i,j),μF=M×N1i=0∑M−1j=0∑N−1F(i,j)
σ F = ( 1 M × N − 1 ∑ i = 0 M − 1 ∑ j = 0 N − 1 [ F ( i , j ) − μ F ] 2 ) 1 2 \sigma_{F}=(\frac{1}{M \times N-1} \sum_{i=0}^{M-1} \sum_{j=0}^{N-1}\left[F(i, j)-\mu_{F}\right]^{2})^{\frac{1}{2}} σF=(M×N−11i=0∑M−1j=0∑N−1[F(i,j)−μF]2)21
σ O = ( 1 M × N − 1 ∑ i = 0 M − 1 ∑ j = 0 N − 1 [ O ( i , j ) − μ O ] 2 ) 1 2 \sigma_{O}=(\frac{1}{M \times N-1} \sum_{i=0}^{M-1} \sum_{j=0}^{N-1}\left[O(i, j)-\mu_{O}\right]^{2})^{\frac{1}{2}} σO=(M×N−11i=0∑M−1j=0∑N−1[O(i,j)−μO]2)21
σ O F = 1 M × N − 1 ∑ i = 0 M − 1 ∑ j = 0 N − 1 [ O ( i , j ) − μ O ] [ F ( i , j ) − μ F ] \sigma_{O F}=\frac{1}{M \times N-1} \sum_{i=0}^{M-1} \sum_{j=0}^{N-1}\left[O(i, j)-\mu_{O}\right]\left[F(i, j)-\mu_{F}\right] σOF=M×N−11i=0∑M−1j=0∑N−1[O(i,j)−μO][F(i,j)−μF]
c 1 = ( k 1 L ) 2 , c 2 = ( k 2 L ) 2 c_1=(k_1L)^2,c_2=(k_2L)^2 c1=(k1L)2,c2=(k2L)2,对于8位灰度的图像 L = 255 L=255 L=255,常数 k 1 = 0.01 , k 2 = 0.03 k_1=0.01,k_2=0.03 k1=0.01,k2=0.03
SSIM值越大,图像质量越高。
Image Enhancement Factor (IEF)
I E F = ∑ i = 0 M − 1 ∑ j = 0 N − 1 [ X ( i , j ) − O ( i , j ) ] 2 ∑ i = 0 M − 1 ∑ j = 0 N − 1 [ F ( i , j ) − O ( i , j ) ] 2 \mathrm{IEF}=\frac{\sum_{i=0}^{M-1} \sum_{j=0}^{N-1}[X(i, j)-O(i, j)]^{2}}{\sum_{i=0}^{M-1} \sum_{j=0}^{N-1}[F(i, j)-O(i, j)]^{2}} IEF=∑i=0M−1∑j=0N−1[F(i,j)−O(i,j)]2∑i=0M−1∑j=0N−1[X(i,j)−O(i,j)]2
IEF值越大,图像质量越高。
Universal Quality Index (UQI)
U Q I = 4 μ O μ F σ O F ( μ O 2 + μ F 2 ) ( σ O 2 + σ F 2 ) \mathrm{UQI}=\frac{4 \mu_{O} \mu_{F} \sigma_{O F}}{\left(\mu_{O}^{2}+\mu_{F}^{2}\right)\left(\sigma_{O}^{2}+\sigma_{F}^{2}\right)} UQI=(μO2+μF2)(σO2+σF2)4μOμFσOF
UQI值越大,图像质量越高。
# -*- coding:utf-8 -*-
import numpy as np
class ImageEvalue(object):
def image_mean(self, image):
mean = np.mean(image)
return mean
def image_var(self, image, mean):
m, n = np.shape(image)
var = np.sqrt(np.sum((image - mean) ** 2) / (m * n - 1))
return var
def images_cov(self, image1, image2, mean1, mean2):
m, n = np.shape(image1)
cov = np.sum((image1 - mean1) * (image2 - mean2)) / (m * n - 1)
return cov
def PSNR(self, O, F):
'''
:param O: 原始图像
:param F: 滤波后的图像
'''
MES = np.mean((np.array(O) - np.array(F)) ** 2)
PSNR = 10 * np.log10(255 ** 2 / MES)
return PSNR
def SSIM(self, O, F):
'''
:param O: 原始图像
:param F: 滤波后的图像
'''
c1 = (0.01 * 255) ** 2
c2 = (0.03 * 255) ** 2
meanO = self.image_mean(O)
meanF = self.image_mean(F)
varO = self.image_var(O, meanO)
varF = self.image_var(O, meanF)
covOF = self.images_cov(O, F, meanO, meanF)
SSIM = (2 * meanO * meanF + c1) * (2 * covOF + c2) / (
(meanO ** 2 + meanF ** 2 + c1) * (varO ** 2 + varF ** 2 + c2))
return SSIM
def IEF(self, O, F, X):
'''
:param O: 原始图像
:param F: 滤波后的图像
:param X: 噪声图像
'''
IEF = np.sum((X - O) ** 2) / np.sum((F - O) ** 2)
return IEF
def UQI(self, O, F):
'''
:param O: 原始图像
:param F: 滤波后的图像
'''
meanO = self.image_mean(O)
meanF = self.image_mean(F)
varO = self.image_var(O, meanO)
varF = self.image_var(F, meanF)
covOF = self.images_cov(O, F, meanO, meanF)
UQI = 4 * meanO * meanF * covOF / ((meanO ** 2 + meanF ** 2) * (varO ** 2 + varF ** 2))
return UQI