How I make color calibration in opencv using a colorchecker?

12,083

Are you asking how to do color calibration or how to do it with OpenCV?

In order to do color calibration you use the last row (gray tones) of the calibration board. Here is what you should do for color calibration step by step:

  1. Capture an image and take small regions inside the gray regions. 10x10 pixels in the middle should be fine. After this step you will have 6 10x10 regions.
  2. Take the average value of the 10x10 region for each gray region. After this step you will have 6 average values, 1 for each gray region. And remember, each value is an RGB value, like the values given below each color.
  3. Check the average values and try to match the values with given values. In the first try most probably the average values are different then the given values. Actually making them match is the calibration operation. To make them match you should change the gains of your camera. Change gain of each channel and try to match the average values with given values.
  4. After you change the camera gains for each channel, repeat these until it converges and camera is calibrated.

You can check if the calibration is done correctly by taking a small region from another color and check its average value with its given value. If they matches or pretty much same, then you have color calibrated your camera successfully.

All you need to do is being able to set camera gains, after that just capture images and try to match values and find correct camera gains.

If you understand the process, doing this using OpenCV should be piece of cake.

[EDIT]

Well, I don't know any ways to calculate the gain. But the most easy way is brute force. You can do something like this;

suppose your gain values vary between 0.0 and 3.0, specify a step value such as 0.1 and try all values. You should have a for loop like this:

for (double redGain=0.0; redGain <= 3.0; redGain += 0.1)
   for (double greenGain=0.0; greenGain <= 3.0; greenGain += 0.1)
      for (double blueGain=0.0; blueGain<= 3.0; blueGain+= 0.1)
         setCameraGain(redGain, greenGain, bluegain);
         // do the rest of the stuff
      end
   end
end
Share:
12,083
aliel
Author by

aliel

Updated on June 17, 2022

Comments

  • aliel
    aliel about 2 years

    I have a image of the colorchecker get by a digital camera, how i use this to calibrate the images using opencv?

    follow below the colorchecker image:

    enter image description here

    • baci
      baci over 10 years
      I guess you mean "color correction" of the pixels here..
  • aliel
    aliel over 10 years
    but how I calculate this gain, for example if I obtain average in the first RGB(250,250,250) and the given values is (246,246,247), difference (4,4,3) and the second (200,200,200) and the given values is (207,207,209) resulting in (-7,-7,-9). What would be the gain, this could be the average between the differences obtained?
  • Rosa Gronchi
    Rosa Gronchi about 9 years
    You describe a somewhat strange white balance algorithm. This is quite different from color calibration
  • guneykayim
    guneykayim about 9 years
    @RosaGronchi then I'll be glad if you can tell the correct color calibration?
  • Rosa Gronchi
    Rosa Gronchi about 9 years
    that depends on the input, but assuming you have the raw (demosaiced) image, you need to compute a 3x3 matrix that maps the camera colors to your preferred color space (e.g. sRGB). That is at least the first order approximation.
  • David Doria
    David Doria almost 8 years
    @RosaGronchi Can you set this up as a least squares problem that solves for a the 3x3 matrix elements that make the observed colors match the known colors as best as possible?
  • Will
    Will almost 4 years
    @RosaGronchi do you still available to comment about this matter? Could you please elaborate a little bit more? I am quite interested on that matter. Thanks a lot.