使用 Python 根据直方图调整曝光(亮度/对比度)
问题描述
我正在尝试用 Python 制作一个带有 GUI(很可能使用 Kivy)的程序,以匹配两个图像的曝光.我想将两个图像(RGB 或灰度)与其相应的直方图并排显示,并有一个滑块来控制所选图像的曝光.我想就如何解决这个问题提出一些建议.
I'm trying to make a program with a GUI (most likely using Kivy) in Python to match the exposure of two images. I want to display both images (RGB or grayscale) side by side with their corresponding histograms and have a slider to be able to control the exposure on the selected image. I would like some advise on how to go about this.
到目前为止,我已经阅读了几篇文章,似乎有几种方法可以计算图像的直方图(numpy、matplotlib、openCV 和 PIL),但是我对哪种方法最好(最少库/要安装的依赖项)供我实施.我还阅读了有关更改图像曝光的内容,有些人提到更改亮度和对比度,所以您需要同时更改两者以更改曝光?我知道openCV有equalizeHist,但它会自动完成,我希望两张图像都尽可能接近整体曝光;这就是为什么我正在考虑手动执行此操作.如果能自动完成就好了,不过我还在想怎么做.
So far I have read several posts and there seem to be several ways to approach calculating the histogram of an image (numpy, matplotlib, openCV, and PIL), however I'm confused about which would be best (least libraries/dependencies to install) for me to implement. I have also read about changing the exposure on an image and some people mention changing brightness and contrast, so you need to change both to change exposure? I know openCV has equalizeHist but that does it automatically and what I would like is for both images to have as close as possible overall exposure; that's why I was thinking of doing it manually. It would be great if could do it automatically, but I'm still thinking on how to do it.
我知道你们非常重视自己的时间,所以如果你们没有时间深入回答这个问题,我会理解的.
I know you guys place tremendous value on your time so I'll understand if you don't have time to answer this in depth.
解决方案
我们有一个直方图调整的例子 这里
We have an example of histogram adjustment here
不过,您似乎对直方图匹配感兴趣.我有一些用于此目的的代码这里,但它没有经过很好的测试.
It sounds as though you are interested in histogram matching, though. I have some code for that purpose here, but it is not well tested.
如果您确实发现该代码有用,请随时向 scikit-image 提出拉取请求,我们可以尝试将其集成到包中.
If you do find that code useful, feel free to make a pull request to scikit-image and we can try to integrate it into the package.
编辑 2019-04-29: 直方图匹配是 现在包含在 scikit-image 中.
相关文章