直方图均衡就是找到一个变换函数,该函数产生有均匀直方图的输出图像。注意要保证输出灰度范围和输入灰度范围相同。
如果一副图像经过均衡后,其像素占有全部可能的灰度级范围,并且均匀分布,则这样的图像有高对比度和多变的灰度色调。、
from skimage import io,exposure,data
import numpy as np
import matplotlib.pyplot as plt
img = data.moon()
plt.figure('hist',figsize = (8,8))
arr = img.flatten()
plt.subplot(221) #第一行左图
plt.imshow(img,plt.cm.gray)
plt.subplot(222)
plt.hist(arr,bins = 256,density = 1,facecolor = 'green',alpha = 0.75)
new_img = exposure.equalize_hist(img) #直接均衡化的函数 Return image after histogram equalization.
arr1 = new_img.flatten()
plt.subplot(223)
plt.imshow(new_img,plt.cm.gray)
plt.subplot(224)
plt.hist(arr1,bins = 256,density = 1,facecolor = 'red',alpha = 0.75)
plt.show()