python实现图像直方图均衡

def histeq(img,nbr_bins=256):
    """ Histogram equalization of a grayscale image. """


    imhist, bins = np.histogram(img.flatten(), nbr_bins, normed = True)

    cdf = imhist.cumsum() # cumulative distribution function
    cdf = 255 * cdf /cdf[-1] 

    # 获取s,并用s替换原始图像对应的灰度值
    result = np.interp(img.flatten(),bins[:-1],cdf)

    return result.reshape(img.shape),cdf

你可能感兴趣的:(我的Python学习,opencv)