打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Histogram matching

This example demonstrates the feature of histogram matching. It manipulates thepixels of an input image so that its histogram matches the histogram of thereference image. If the images have multiple channels, the matching is doneindependently for each channel, as long as the number of channels is equal inthe input image and the reference.

Histogram matching can be used as a lightweight normalisation for imageprocessing, such as feature matching, especially in circumstances where theimages have been taken from different sources or in different conditions (i.e.lighting).

import matplotlib.pyplot as pltfrom skimage import datafrom skimage import exposurefrom skimage.transform import match_histogramsreference = data.coffee()image = data.chelsea()matched = match_histograms(image, reference, multichannel=True)fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(8, 3),                                    sharex=True, sharey=True)for aa in (ax1, ax2, ax3):    aa.set_axis_off()ax1.imshow(image)ax1.set_title('Source')ax2.imshow(reference)ax2.set_title('Reference')ax3.imshow(matched)ax3.set_title('Matched')plt.tight_layout()plt.show()

To illustrate the effect of the histogram matching, we plot for eachRGB channel, the histogram and the cumulative histogram. Clearly,the matched image has the same cumulative histogram as the referenceimage for each channel.

fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(8, 8))for i, img in enumerate((image, reference, matched)):    for c, c_color in enumerate(('red', 'green', 'blue')):        img_hist, bins = exposure.histogram(img[..., c], source_range='dtype')        axes[c, i].plot(bins, img_hist / img_hist.max())        img_cdf, bins = exposure.cumulative_distribution(img[..., c])        axes[c, i].plot(bins, img_cdf)        axes[c, 0].set_ylabel(c_color)axes[0, 0].set_title('Source')axes[0, 1].set_title('Reference')axes[0, 2].set_title('Matched')plt.tight_layout()plt.show()

Total running time of the script: ( 0 minutes 0.433 seconds)

Gallery generated by Sphinx-Gallery

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用直方图处理进行颜色校正
Template Matching
5个有趣的Python脚本,建议收藏!
CVPR 2021-刘虹雨:结合深度神经网络进行有效的图像修复和编辑
【生成模型】解读显式生成模型之完全可见置信网络FVBN
CNN vs. RNN: How are they different? | TechTarget
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服