skimage用于图像的直方图均衡化的函数有两个,分别是equalize_hist和equalize_adapthist函数,本文详细介绍了这两个函数。
equalize_hist(image, nbins=256, mask=None)
skimage.exposure.exposure模块中的函数,返回直方图均衡化之后的图像。
from skimage import data,exposure
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, normed=1,edgecolor='None',facecolor='red') #原始图像直方图
img1=exposure.equalize_hist(img) #进行直方图均衡化
arr1=img1.flatten() #返回数组折叠成一维的副本
plt.subplot(223)
plt.imshow(img1,plt.cm.gray) #均衡化图像
plt.subplot(224)
plt.hist(arr1, bins=256, normed=1,edgecolor='None',facecolor='red') #均衡化直方图
plt.show()
[1] http://www.janeriksolem.net/2009/06/histogram-equalization-with-python-and.html
[2] http://en.wikipedia.org/wiki/Histogram_equalization
equalize_adapthist(image, *args, **kwargs)
skimage.exposure._adapthist模块里的函数,有限对比度自适应直方图均衡(CLAHE,Contrast Limited Adaptive Histogram Equalization)。一种局部对比度增强的算法,该算法使用在图像的不同平铺区域上计算的直方图。因此,即使在比大多数图像更暗或更轻的区域中,局部细节也可以得到增强。
参数名:image
类型:(M, N[, C]) ndarray
说明:输入图像
参数名:kernel_size
类型: integer or list-like, optional
说明:定义算法中使用的上下文区域的形状。如果通过迭代,它必须具有与图像的ndim(没有颜色通道)相同数量的元素。如果是整数,则将其广播到每个图像维度。默认情况下,核的大小是图像高度的1/8,宽度的1/8。
对于彩色图像,执行以下步骤:
[1] http://tog.acm.org/resources/GraphicsGems/
[2] https://en.wikipedia.org/wiki/CLAHE#CLAHE
from skimage import data,exposure
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, normed=1,edgecolor='None',facecolor='red') #原始图像直方图
img1=exposure.equalize_adapthist(img) #进行自适应直方图均衡化
arr1=img1.flatten() #返回数组折叠成一维的副本
plt.subplot(223)
plt.imshow(img1,plt.cm.gray) #均衡化图像
plt.subplot(224)
plt.hist(arr1, bins=256, normed=1,edgecolor='None',facecolor='red') #均衡化直方图
plt.show()