SSIM
SSIM简介
SSIM也叫做结构相似性,是一种衡量两幅图像相似度的指标,经常用作图像质量的评价。
评价指标包括亮度、对比度和结构比较
简化后的公式如下:
并且SSIM具有对称性,即:
S
S
I
M
(
x
,
y
)
=
S
S
I
M
(
y
,
x
)
SSIM(x,y) = SSIM(y,x)
SSIM(x,y)=SSIM(y,x)
SSIM输出的值越接近1,证明两张图像越相似,当输入图片相同时,即:
S
S
I
M
(
x
,
x
)
=
1
SSIM(x,x)=1
SSIM(x,x)=1
SSIM代码
SSIM被tensorflow收录,所以可以直接调用。
# Read images from file.
im1 = tf.decode_png('path/to/im1.png')
im2 = tf.decode_png('path/to/im2.png')
# Compute SSIM over tf.uint8 Tensors.
ssim1 = tf.image.ssim(im1, im2, max_val=255)
# Compute SSIM over tf.float32 Tensors.
im1 = tf.image.convert_image_dtype(im1, tf.float32)
im2 = tf.image.convert_image_dtype(im2, tf.float32)
ssim2 = tf.image.ssim(im1, im2, max_val=1.0)
# ssim1 and ssim2 both have type tf.float32 and are almost equal.
tf.image.ssim(img1,img2,max_val) 参数:
img1:第一批图像.
img2:第二批图像.
max_val:图像的动态范围(即最大允许值与最小允许值之间的差值).
返回:一个包含批处理中每个图像的SSIM值的张量.返回的SSIM值在范围(-1,1)中
PSNR
PSNR简介
PSNR也叫峰值信噪比,是一种应用普遍的客观测量法,它是原图像与处理后的图像之间的均方误差相对于信号最大值的平方,单位是dB。
P
S
N
R
=
10
∗
l
o
g
10
(
M
A
X
I
2
M
S
E
)
PSNR=10*log_{10}\quad({MAX_I^2 \over \sqrt{MSE}})
PSNR=10∗log10(MSEMAXI2)
但是PSNR的分数高不代表和人眼看到的感受相同,听说IFC和NQM的效果更好。
PSNR代码
PSNR也被tensorflow收录,所以也可以直接调用。
# Read images from file.
im1 = tf.decode_png('path/to/im1.png')
im2 = tf.decode_png('path/to/im2.png')
# Compute PSNR over tf.uint8 Tensors.
psnr1 = tf.image.psnr(im1, im2, max_val=255)
# Compute PSNR over tf.float32 Tensors.
im1 = tf.image.convert_image_dtype(im1, tf.float32)
im2 = tf.image.convert_image_dtype(im2, tf.float32)
psnr2 = tf.image.psnr(im1, im2, max_val=1.0)
# psnr1 and psnr2 both have type tf.float32 and are almost equal.
以上两种得到的结果都是一样的。
tf.image.psnr(a,b,max_val,name=None)
参数:a:第一组图像.
b:第二组图像.
max_val:图像的动态范围(即最大允许值和最小允许值之间的差值).
name:用于嵌入计算的命名空间.
除此之外,也可以自己编写函数
def psnr(img1, img2):
mse = np.mean((img1/1.0 - img2/1.0) ** 2 )
if mse < 1.0e-10:
return 100
return 10 * math.log10(255.0**2/mse)
img1 = cv2.imread('path1')
img2 = cv2.imread('path2')
print(psnr(img1, img2))