我该如何平衡对比度和放大器;使用OpenCV的图像亮度? [英] How do I equalize contrast & brightness of images using opencv?
问题描述
我已经得到了我扫描的图像,但白皮书不是白色的屏幕上。有没有办法来平衡合约/亮度使背景更白?
I've got an image that I've scanned, but the white paper is not white on the screen. Is there a way to equalize the contract/brightness to make the background whiter?
更新
我试过从EmguCv建议Image._EqualizeHist功能:
I've tried the suggested Image._EqualizeHist function from EmguCv:
string file = @"IMG_20120512_055533.jpg";
Image<Bgr, byte> originalColour = new Image<Bgr, byte>(file);
Image<Bgr, byte> improved = originalColour.Clone();
improved._EqualizeHist();
但得到一个更糟糕的结果(也当第一灰度缩放):
But get an even worse result (also when first gray scaled):
我失去了其他的参数?
推荐答案
我在这里讨论了一些技巧:的我怎样才能调整关于C中OpenCV的反差?
I have discussed some techniques here : How can I adjust contrast in OpenCV in C?
请检查一下。下面是我得到时,我最后两个方法想你的图片
Please check it. Below are the results i got when i tried last two methods on your image
1)阈值的结果:
阈值给出了一个二值图像。如果这是你想要的,你可以申请什么阈值函数
Thresholding gives a binary image. If that is what you want you can apply threshold function
2)如果灰度图像所需
其他:
形态闭
也工作,你的情况
img = cv2.imread('home.jpg',0)
kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
close = cv2.morphologyEx(gray,cv2.MORPH_CLOSE,kernel1)
div = np.float32(gray)/(close)
res = np.uint8(cv2.normalize(div,div,0,255,cv2.NORM_MINMAX))
(在Python API代码)
(code in Python API)
结果如下图:
这篇关于我该如何平衡对比度和放大器;使用OpenCV的图像亮度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!