DIDSR / eeDAP

Evaluation Environment for Digital and Analog Pathology
http://didsr.github.io/eeDAP/
Other
16 stars 21 forks source link

Camera white balance problem #76

Open qigongFDA opened 6 years ago

qigongFDA commented 6 years ago

There is white balance problem for camera (camera image looks green or red). We need to improve the white balance to fix this problem. It can improve the registration accuracy.

qigongFDA commented 6 years ago

Here are the emails from and to pointgrey camera supporter.

From supporter Thank you for sending me the screenshot. It seems like your image is greenish/yellow. Could you let me know the camera model you are testing, and the software you are using to grab the images? Lastly, could you send me another screenshot of camera's white balance settings?

To supporter I use matlab to get image by following commands cam_format=char('F7_RGB_1224x1024_Mode1'); cam_adaptor = 'pointgrey'; cam = videoinput(cam_adaptor,1,cam_format) imaqhwinfo(cam) cam.Tag = 'Microscope Camera Object'; cam.TriggerRepeat = 0; cam.FramesPerTrigger = 10; cam.FrameGrabInterval = 1; cam_src = getselectedsource(cam); cam_src.WhiteBalanceRBMode = 'Off';

From supporter Thank you for your email, and clarifying the software you are using. The issue you are encountering, where the initial whitebalance setting in Matlab causes the images to appear green, is something we are aware of and have reported to Matlab. Could you try setting the Whitebalancing setting to Manual mode, and try adjusting the white balance settings until you are satisfied with the color you get from the camera?

To supporter This is the screen cut of matlab Image Acquisition Tool. Do you mean I should try number by number to get image to white? Do you have any suggestion about how to adjust the 2 number (increase or decrease)? After I turn off and reopen everything, do I need to set it again? Thank you

From supporter Thank you for your email. I would suggest setting the two numbers (red/blue color channel) to 512 and adjust the settings from their depending on the resulting image. If the image looks too red, you can reduce the first number, if the image appears too blue, you can reduce the second number Also, once you restart Matlab, you will have to reset the white balance setting again.

qigongFDA commented 6 years ago

With Wei-Chung's help, we find a white balance setting [587 710], which can generate image for blank area with intensity [208,210,194]. It is close to our desire color (three channels has same intensity).

I fix the white balance setting in eeDAP to [587 710].

We want to find a automatic method to find the white balance setting. The optimal intensity is [255,255,255].

qigongFDA commented 6 years ago

White balance setting information for manufacture supporter

As we talked in KB http://www.ptgrey.com/KB/10251, White balance is a name given to a system of color correction to deal with differing lighting conditions. Adjusting the white balance by modifying the relative gain of R, G and B in an image enables white areas to look "whiter". Taking some subset of the target image and looking at the relative red to green and blue to green response, the general idea is to scale the red and blue channels so that the response is 1:1:1.

So if we want to get 1:1:1 R,G,B, that means GainR = G(avg)/R(avg) and GainB = G(avg)/B(avg).

We define Red, Green and Blue all “starts off” as 512. (played around with a camera and you can see that setting both Red and Blue to 512, you get the same results as WB being turned off. )

To calculate to DB , as we talked in section 1, we should use the second way to get DB. In flycapture, if we set 256 , (if Green value is still 512), then we use 20lg(n) to calculate, so n = 512/256 =2 , 20lg(2) = 6

That means 2 multiple is 6db, 1 multiple is 0db, 1/2 multiple is -6db.

If we set 600, then n = 512/600 = 0.853 , 20lg(0.853) = -1.37dB.

qigongFDA commented 6 years ago

White balance setting information for manufacture supporter

PGR use the formula below to get the WB value which we set in flycapture setting

¼ mutilple means WB = 0 = log_2(1/4)x256 +512

1 multiple means WB = 512 = log_2(1)x256 + 512

two multiple menas WB = 768 = log_2(2)x256 + 512

four multiple means WB = 1024 = log_2(4)x256 + 512

So by my calculations (Histogram shows average RGB as 204, 200, 62.) , I need to set my red and blue as follows:

R = log2(Gavg/Ravg) * 256 + 512

= log2(0.98) * 256 + 512

= -0.03*256 + 512

= approximately 504

G = log2(Gavg/Bavg) * 256 + 512

= log2(3.22) * 256 + 512

= 1.69 * 256 + 512 = 944

So that is what I would set the WB registers at.

  1. step 3 To verify, turned on auto-WB, and I got R=501, B=935.
qigongFDA commented 6 years ago

Add function in camera_open.m to adjust white balance.

  1. Automatic adjust at begin of MicroRT mode. User should make sure the microscope is on and viewing a blank area.
  2. Default WB setting is 587 710.
  3. Based on center 20x20 area camera image, calculate average R, G, B intensities.
  4. Compare 3 average intensities, if the difference is larger than 5, use functions in last issue to adjust WB setting.
  5. Repeat step 3, 4.
qigongFDA commented 6 years ago

Move WB adjusting function from camera_open.m to Stage_Allighment.m

  1. Software does automatic color adjusting at begin of global registration (after stage arrives 'original point')
  2. Add a button in camera preview window. User can use it to adjust the color again. This button is only available during global registration.

After review, we can close this issue.