37,722
社区成员
发帖
与我相关
我的任务
分享
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
from PIL import Image
from pylab import *
from numpy import *
import imtools
im= array(Image.open('E:\\daima\\pydaima\\shijue\\tupian1\\gang2.jpg').convert('L'))
im2,cdf =imtools.histeq(im)