自然图像质量评估NIQE 报错AttributeError: module ‘scipy.misc‘ has no attribute ‘imresize‘及代码修改

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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值