How do I equalize contrast & brightness of images using opencv?

前端 未结 5 766
花落未央
花落未央 2020-12-13 10:53

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?

5条回答
  •  北海茫月
    2020-12-13 11:35

    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

提交回复
热议问题