AttributeError:'JpegImageFile' object has no attribute 'flatten' 问题的分析

对于jpeg或其他格式图像,通过PIL的Image读入后,直接进行直方图分析时,调
用flatten时会报出:

    im = Image.open('aaa.jpg')
    AttributeError:'JpegImageFile' object has no attribute 'flatten'

    解决办法:
    转换为数组array。
    im1 = array(im,‘f’)# 由于可能对im1直接进行运算,对整型的像
                           #素数据的除运算,会导致小数丢失。故需要
                           #增加'f'option
     arr = im1.flatten() #将2D 数组变成一个一维数组

猜你喜欢

转载自blog.csdn.net/tbzj_2000/article/details/80409992