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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章