Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
859 views
in Technique[技术] by (71.8m points)

c# - 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?

Update

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):

Am I missing other parameters?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

Thresholding gives a binary image. If that is what you want you can apply threshold function

2) If grayscale image needed :

enter image description here

Additional :

Morphological closing also work good in your case

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))

(code in Python API)

Result Below:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...