在谷歌上搜索直方图均衡化Python或对比度拉伸Python,我被指向了OpenCv中Python文档中的相同链接,它们实际上都与均衡化有关,而不是拉伸(IMO)。
阅读文档,它似乎与措辞混淆,因为它将均衡描述为拉伸操作:
What Histogram Equalization does is to stretch out this range.
以及
So you need to stretch this histogram to either ends (as given in below image, from wikipedia) and that is what Histogram Equalization does (in simple words)
我觉得这是错误的,因为维基百科上没有任何地方说直方图均衡化意味着拉伸,阅读其他资料,他们清楚地区分了这两种操作。
我的问题:
OpenCV文档实际上实现了直方图均衡化,但解释得不好吗?
Python/OpenCV可以使用min_max normalization通过cv2.normalize()方法进行对比拉伸。例如:
输入:
标准化1:
标准化2:
你也可以用一个简单的线性方程来做你自己的拉伸,这个方程有2对输入/输出值,形式是y=a*x+B,并求解这两个联立方程。参见How can I make the gradient appearance of one image equal to the other?中所示的拉伸概念
您也可以使用
cv2.LUT
来进行对比度拉伸,方法是使用np.interp
创建自定义表。它们文档的链接分别是this和this。下面是一个例子。创建的表
现在
cv2.LUT
将用表中的值替换原始图像的值。例如,所有值为1的像素将被0替换,所有值为4的像素将被1替换。原始图像
对比度拉伸图像
可以根据需要改变
xp
和fp
的值来创建自定义表,即使最小和最大像素分别为0和255,与hashcode55提供的答案不同,它也会拉伸对比度。OpenCV没有任何对比度拉伸功能,google也会得到相同的结果,因为直方图均衡化会水平拉伸直方图,但这只是转换函数的差异。(两种方法都增加了图像的对比度。转换函数将像素强度级别从给定范围传输到所需范围。)
直方图均衡化从给定图像的概率密度函数(PDF)自动导出变换函数(TF),在对比度拉伸中,您可以根据应用程序的要求指定自己的TF。
一个可以做对比拉伸的简单TF是
min-max
对比拉伸-对每个像素值执行此操作。最小和最大为最小和最大强度。
相关问题 更多 >
编程相关推荐