Python做图像直方图均衡化处理出错求解答

照计算机视觉编程书敲代码,这一段一直过不去,求解决办法

相关代码

下面是一段程序

from PIL import Image
from numpy import *
import imtools

im==array(Image.open('C:/Users/Administrator/Desktop/blow.png').convert('L'))
im2,cdf=imtolld.hidteq(im)

下面是另一段程序,保存名称为imtools.py

def histeq(im,nbr_bins=256):
    """对一幅灰度图像进行直方图均衡化"""

    #计算图像的直方图
    imhist,bins=histogram(im.flatten(),nbr_bins.normed=True)
    
    cdf=imhist.cumsum()#累积分布函数
    cdf=255*cdf/cdf[-1]#归一化
    
    #使用累积分布函数的线性插值,计算新的像素值
    im2=interp(im.flatten(),bins[:-1],cdf)
    return im2.reshape(im.shape),cdf
    



运行报错,显示:

Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/ppp.py", line 4, in <module>
    import imtools
  File "C:/Users/Administrator/Desktop\imtools.py", line 20
    imhist,bins=histogram(im.flatten(),nbr_bins.normed=True)
SyntaxError: keyword can't be an expression

阅读 1.4k
1 个回答

nbr_bins.normed=True 这错了,keyword can't be an expression关键字不能是表达式,调用函数的关键字可以是normed=True 但是不能是表达式a.b=True

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题