Subtract difference of L-channels

asked 2018-01-03 03:31:51 -0600

mk2706 gravatar image

updated 2018-01-03 03:47:15 -0600

berak gravatar image

Hello guys,

i have a problem with a projekt i´m working on. I want to profile the raspberry pi camera and later do some other stuff with it.

However, my LED´s are illuminating the picture very unevenly, so i have to adjust for it. So the first step i have to do is convert the picture from BGR to LAB and correct the lightness.

Here comes the problem:

I have 2 pictures. Picture A with the profiling Chart and Picture B, which is a white sheet of paper in the exact same position.

My plan was to find the minimum l-channel value in the white picture, subtract this value from the normal lightness of the white picture and then subtract that from the lightness of the Profiling chart.

At the end merge the channels back together and convert back to BGR.

This way the uneven illumination shouldn´t disturb the colors of the chart and the profiling process.

My Script:

import cv2

#-----Reading the image--
Img1 = cv2.imread('Test123_Weiss.jpg', 1)
Img2 = cv2.imread('Test123.jpg', 1)
imgA = cv2.resize(Img1, (800, 600))
imgB = cv2.resize(Img2, (800, 600))
cv2.imshow("img",imgB) 

#-----Converting image to LAB Color model--
labA= cv2.cvtColor(imgA, cv2.COLOR_BGR2LAB)
labB= cv2.cvtColor(imgB, cv2.COLOR_BGR2LAB)
#cv2.imshow("lab",lab)

#-----Splitting the LAB image to different channels--
lA, aA, bA = cv2.split(labA)
lB, aB, bB = cv2.split(labB)

#-----Find L-channel minimum--
(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(lA)

#-----Subtract difference of L-channels--
lv = cv2.subtract(lA,minVal)
lc = cv2.subtract(lB,lv)

#-----Merge the enhanced L-channel with the a and b channel--
limg = cv2.merge((lc,aB,bB))

#-----Converting image from LAB Color model to RGB model--
final = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
cv2.imshow('final', final)

cv2.imwrite('lightness.jpg' ,final)

cv2.waitKey(0)


#_____END_____#

MAybe somebody has an idea how to make this work?

edit retag flag offensive close merge delete

Comments

I'm not sure to understand your problem but may be you can use image mean and std to adjust two images.

LBerger gravatar imageLBerger ( 2018-01-03 03:44:06 -0600 )edit

Ok, i try to clarify :D

If a lamp shines from directly above on a picture, the part in the middle of the picture is more illuminated than the rest of the image. So the colors in the middle of the image are also stronger illuminated and thus slightly "off color" .

I want to correct that by adjusting the lightness (l-channel).

If you have any more questions or if i need to clarify something please jus ask :)

mk2706 gravatar imagemk2706 ( 2018-01-03 04:06:18 -0600 )edit

You can post two images.

"the part in the middle of the picture is more illuminated than the rest of the image" May be you can track this difference using two or three roi in images and keep roi mean constant

LBerger gravatar imageLBerger ( 2018-01-03 04:34:12 -0600 )edit

I can upload the images in few hours, i am currently at work.

But what do you mean with roi? Sorry, i am pretty new to OpenCV :/

mk2706 gravatar imagemk2706 ( 2018-01-03 05:07:38 -0600 )edit

Region Of Interest

LBerger gravatar imageLBerger ( 2018-01-03 05:10:17 -0600 )edit

I think what you want is to find the difference in the L channel between 127 (Pick a visually appropriate number here) and the white image. Then add that difference to the L channel of the Profile Chart.

If your white image is dark, then 127 - white is large, so you that brightens the other. If it's bright, then 127 - white is negative, so it darkens the other.

Tetragramm gravatar imageTetragramm ( 2018-01-04 17:48:22 -0600 )edit