Increase image brightness without overflow

I had a problem while trying to increase the brightness of the image.

Here is the source image:

enter image description here

The image I wanted to get is as follows:

enter image description here

Now, to increase the brightness with the following code:

    image = cv2.imread("/home/wni/vbshare/tmp/a4_index2.png",0)

    if sum(image[0])/len(image[0])<200:
        new = np.where((255-image)<image,255,image*2)
    else:
        new = image
    return new

And I got the following image:

enter image description here

So, it seems that the brightness of some points is overflowing.

And I tried to change the threshold from 200 to some other number, for example. 125, 100, 140.etc However, the brightness of the image remains almost the same dark or crowded.

Env:

Python: 2.7.10

Opencv: 3.2.0

Any suggestion for this is appreciated.

Thanks.

+6
source share
2 answers

. , .

NB. OpenCV 2.4.x, 3.x.

0

.

img = cv2.imread('paper.jpg',0)

1

, . -.

dilated_img = cv2.dilate(img, np.ones((7,7), np.uint8)) 

Dilated

2

.

, / .

bg_img = cv2.medianBlur(dilated_img, 21)

Blurry

3

, . , , ( 0 ), ( ).

, .

diff_img = 255 - cv2.absdiff(img, bg_img)

Inverted Difference

4

, .

norm_img = diff_img.copy() # Needed for 3.x compatibility
cv2.normalize(diff_img, norm_img, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)

Normalized

5

. .

_, thr_img = cv2.threshold(norm_img, 230, 0, cv2.THRESH_TRUNC)
cv2.normalize(thr_img, thr_img, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)

Gray trimmed

...

, ;) , -, .


. , (16+ int float) , .

+9

. , , , ( ). :

cutoff_val = 100 # everything above this is set to set_color
set_color = 255 
ret,thresh_img = cv2.threshold(image,cutoff_val,set_color,cv2.THRESH_BINARY)

, , , .

, , - , , !

: , , .

cutoff_val = 150 # everything above this is set to the cutoff val
set_color = 255 # if 
ret,thresh_img = cv2.threshold(image,cutoff_val,set_color,cv2.THRESH_TRUNC)
window_sz = 3
thresh_img2 = cv2.adaptiveThreshold(thresh_img,set_color,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
            cv2.THRESH_BINARY,window_sz,2)
+2

Source: https://habr.com/ru/post/1017343/


All Articles