text
stringlengths
1
93.6k
Email: chenxuelei@hotmail.com
Usage:
python evaluate.py RESULT_PATH REFERENCE_PATH
'''
import numpy as np
from skimage.measure import compare_psnr, compare_ssim
import math
import sys
from skimage import io, color, filters
import os
import math
def rmetrics(a,b):
#pnsr
mse = np.mean((a-b)**2)
psnr = 10*math.log10(1/mse)
#ssim
ssim = compare_ssim(a,b,multichannel=True)
return psnr, ssim
def nmetrics(a):
rgb = a
lab = color.rgb2lab(a)
gray = color.rgb2gray(a)
# UCIQE
c1 = 0.4680
c2 = 0.2745
c3 = 0.2576
l = lab[:,:,0]
#1st term
chroma = (lab[:,:,1]**2 + lab[:,:,2]**2)**0.5
uc = np.mean(chroma)
sc = (np.mean((chroma - uc)**2))**0.5
#2nd term
top = np.int(np.round(0.01*l.shape[0]*l.shape[1]))
sl = np.sort(l,axis=None)
isl = sl[::-1]
conl = np.mean(isl[:top])-np.mean(sl[:top])
#3rd term
satur = []
chroma1 = chroma.flatten()
l1 = l.flatten()
for i in range(len(l1)):
if chroma1[i] == 0: satur.append(0)
elif l1[i] == 0: satur.append(0)
else: satur.append(chroma1[i] / l1[i])
us = np.mean(satur)
uciqe = c1 * sc + c2 * conl + c3 * us
# UIQM
p1 = 0.0282
p2 = 0.2953
p3 = 3.5753
#1st term UICM
rg = rgb[:,:,0] - rgb[:,:,1]
yb = (rgb[:,:,0] + rgb[:,:,1]) / 2 - rgb[:,:,2]
rgl = np.sort(rg,axis=None)
ybl = np.sort(yb,axis=None)
al1 = 0.1
al2 = 0.1
T1 = np.int(al1 * len(rgl))
T2 = np.int(al2 * len(rgl))
rgl_tr = rgl[T1:-T2]
ybl_tr = ybl[T1:-T2]
urg = np.mean(rgl_tr)
s2rg = np.mean((rgl_tr - urg) ** 2)
uyb = np.mean(ybl_tr)
s2yb = np.mean((ybl_tr- uyb) ** 2)
uicm =-0.0268 * np.sqrt(urg**2 + uyb**2) + 0.1586 * np.sqrt(s2rg + s2yb)
#2nd term UISM (k1k2=8x8)
Rsobel = rgb[:,:,0] * filters.sobel(rgb[:,:,0])
Gsobel = rgb[:,:,1] * filters.sobel(rgb[:,:,1])
Bsobel = rgb[:,:,2] * filters.sobel(rgb[:,:,2])
Rsobel=np.round(Rsobel).astype(np.uint8)
Gsobel=np.round(Gsobel).astype(np.uint8)
Bsobel=np.round(Bsobel).astype(np.uint8)
Reme = eme(Rsobel)
Geme = eme(Gsobel)
Beme = eme(Bsobel)
uism = 0.299 * Reme + 0.587 * Geme + 0.114 * Beme
#3rd term UIConM
uiconm = logamee(gray)