python图像直方图均衡化
时间: 2023-10-24 22:08:27 浏览: 133
直方图均衡化是一种能够提高图像对比度的方法,它可以通过重新分布图像的灰度级来扩展动态范围,使图像更加清晰。在Python中,可以使用scikit-image库中的exposure模块来实现直方图均衡化。下面是一个示例代码:
import numpy as np
from skimage import exposure, data
import matplotlib.pyplot as plt
# 读取图像
img = data.moon()
# 进行直方图均衡化
img_eq = exposure.equalize_hist(img)
# 显示原始图像和均衡化后的图像以及它们的直方图
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 8))
ax = axes.ravel()
# 原始图像
ax.imshow(img, cmap=plt.cm.gray)
ax.set_title('Original Image')
# 原始图像的直方图
ax.hist(img.flatten(), bins=256, color='red', alpha=0.5, histtype='stepfilled')
ax.set_title('Histogram of Original Image')
# 均衡化后的图像
ax.imshow(img_eq, cmap=plt.cm.gray)
ax.set_title('Equalized Image')
# 均衡化后的图像的直方图
ax.hist(img_eq.flatten(), bins=256, color='red', alpha=0.5, histtype='stepfilled')
ax.set_title('Histogram of Equalized Image')
# 显示图像和直方图
plt.tight_layout()
plt.show()
阅读全文
相关推荐

















