python - OpenCV_Python: Lightness Channel Manipulation, Trying to get same brightness to all images -


i hoping fix uneven brightness/lightness of images(hoping brightness). after getting difference in lightness channel loop images reference images. add difference , save new images...however after checking new images, realised still gotten uneven brightness...is there wrong coding??? or correction appreciated. have tried code on both lab , hsv colorspace, still same. below code , couple of result got.

from pil import image import numpy np import cv2   path = 'r:\\temp\\ming\\alignedphoto_in_png\\' path1 = 'r:\\temp\\ming\\testing1\\'   img = cv2.imread(path + 'aligned_img_1770.png') img = cv2.cvtcolor(img, cv2.color_bgr2lab) = np.mean(img[:,:,0])  in range (1770,1869):     img1 = cv2.imread(path + 'aligned_img_%d.png'%(i))     img1 = cv2.cvtcolor(img1, cv2.color_bgr2lab)     img1[:,:,0], img1[:,:,1], img1[:,:,2] = cv2.split(img1)     print(img1[:,:,0])     b = np.mean(img1[:,:,0])     diff= b-a     print(diff)     img1[:,:,0] = img1[:,:,0] + diff     img1 = cv2.merge([img1[:,:,0], img1[:,:,1], img1[:,:,2]])     print(img1[:,:,0])     img1 = cv2.cvtcolor(img1, cv2.color_lab2bgr)     cv2.imwrite(path1 + 'testing1_%d.png'%(i), img1) 

also, guidance on how can edit existing code make sure after adding difference, new value not exceed max/min range of lightness channel in lab or max/min range of value channel in hsv? realised after addition if new value >255 , value jump starting counting 1. googled around on how fix or set range dun understand how it

below few images result got above code. identify went wrong code still getting uneven brightness new images after adding difference.

[[ 39  39  39 ...,  38  38  36]  [ 39  38  39 ...,  39  39  39]  [ 40  40  40 ...,  39  39  39]  ...,   [119 119 122 ..., 165 166 167]  [118 118 120 ..., 169 166 166]  [115 116 117 ..., 175 169 167]] 0.0 [[ 39  39  39 ...,  38  38  36]  [ 39  38  39 ...,  39  39  39]  [ 40  40  40 ...,  39  39  39]  ...,   [119 119 122 ..., 165 166 167]  [118 118 120 ..., 169 166 166]  [115 116 117 ..., 175 169 167]] [[  0   0   0 ...,   0   0   0]  [  0   0   0 ...,   0   0   0]  [  0   0   0 ...,   0   0   0]  ...,   [117 119 119 ..., 165 163 131]  [117 117 118 ..., 170 166 131]  [115 116 116 ..., 176 171 134]] -1.48181156101 [[255 255 255 ..., 255 255 255]  [255 255 255 ..., 255 255 255]  [255 255 255 ..., 255 255 255]  ...,   [115 117 117 ..., 163 161 129]  [115 115 116 ..., 168 164 129]  [113 114 114 ..., 174 169 132]] [[  0   0   0 ...,   0   0   0]  [  0   0   0 ...,   0   0   0]  [  0   0   0 ...,   0   0   0]  ...,   [  0  97 115 ..., 165 164 165]  [  0  96 114 ..., 169 166 164]  [  0  95 113 ..., 175 170 166]] -3.69765536832 [[253 253 253 ..., 253 253 253]  [253 253 253 ..., 253 253 253]  [253 253 253 ..., 253 253 253]  ...,   [253  93 111 ..., 161 160 161]  [253  92 110 ..., 165 162 160]  [253  91 109 ..., 171 166 162]] 

that's why maths skill every programmer should have.

you correct brightness adding diff.

so if want equal sum of b , diff

a = b + diff 

and know , be. how diff?

diff = - b 

not

diff = b - 

otherwise make darker images darker , brighter images brighter instead of bringing them reference mean a...

of course using global offset cause problems pixels exceed value range. have work around problem. otherwise new mean wrong.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -