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?
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 :
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:
To change brightness and contrast, you can multiply your pixel values and then add some constant to them. (More info on Changing the contrast and brightness of an image, in OpenCV docs.)
Using python and numpy:
import cv2 as cv
import numpy as np
img = cv.imread('b.jpg',0) # loads in grayscale
alpha = 1
beta = 0
res = cv.multiply(img, alpha)
res = cv.add(res, beta)
You can also just use:
res = cv.convertScaleAbs(img, alpha = alpha, beta = beta)
In your image, you can check in histogram that the maximum values are around 170 (actually, it is 172, if you use img.max()
). So, you can multiply your image by 255/172 = 1.48
to increase brightness.
See the results below:
And the histograms, respectively:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With