NIQE链接:https://github.com/guptapraful/niqe
他的指征是数字越小效果越好。
报错原因是是新版本的Scipy和Pillow库已经弃用这些函数
imresize is deprecated! imresize is deprecated in SciPy 1.0.0, and will be removed in 1.3.0. Use Pillow instead: numpy.array(Image.fromarray(arr).resize())
.
scipy.misc.imresize — SciPy v1.2.1 Reference Guide
要么降版本降到1.0.0,要么改接口,懒的重新配环境,我尝试了一下改接口
在niqe.py的173行,将
img2 = scipy.misc.imresize(img, 0.5, interp='bicubic', mode='F')
改为
img2 = np.array(Image.fromarray(img).resize((int(img.shape[1] * 0.5), int(img.shape[0] * 0.5)), resample=Image.BICUBIC))
即可正常运行
运行之后他只会运行测试图片,需要将代码修改:
将
# ref = np.array(Image.open('./test_imgs/bikes.bmp').convert('LA'))[:,:,0] # ref
# dis = np.array(Image.open('./test_imgs/bikes_distorted.bmp').convert('LA'))[:,:,0] # dis
# print('NIQE of ref bikes image is: %0.3f'% niqe(ref))
# print('NIQE of dis bikes image is: %0.3f'% niqe(dis))
# ref = np.array(Image.open('./test_imgs/parrots.bmp').convert('LA'))[:,:,0] # ref
# dis = np.array(Image.open('./test_imgs/parrots_distorted.bmp').convert('LA'))[:,:,0] # dis
# print('NIQE of ref parrot image is: %0.3f'% niqe(ref))
# print('NIQE of dis parrot image is: %0.3f'% niqe(dis))
替换为
folder = "."
path = folder + "/test_imgs"
files = os.listdir(path)
files = natsort.natsorted(files)
for i in range(len(files)):
file = files[i]
filepath = path + "/" + file
prefix = file.split('.')[0]
if os.path.isfile(filepath):
# print('******** file ********',file)
ref = np.array(Image.open(folder + '/test_imgs/' + file).convert('LA'))[:,:,0]
print(f'NIQE of {file} image is: %0.3f'% niqe(ref))
前面需要import natsort