简体   繁体   中英

Matlab Least Square for calibration RGB

I explained my problem two times because my english is not well :/

first explaining:

I have RGB matrix of each pixel in some image I filmed.

moreover, I have 3 pixels' RGB that I know their real values (after I take a picture, the pixels' RGB values are changed because of light).

How can I use these 3 known RGB in order to use the least squares method so I can get the original image colors accurately?

second explaining:

I have to take some pictures of some apples by my camera. If I will film the same apples in my room and in the street, I will get images that have not the same color of the apples, although these are the same apples. this is bacause the light in the street is not the light in my room.

in order to solve this problem, I want to put three circles (red, green and blue) that I know their RGB, near the apples. For example, I have 3 circles:

red circle -> [241 25 13]

green circle -> [12 239 41]

blue circle -> [35 28 237]

now, I will film the apples with the 3 circles. I know that the RGB of my 3 circles got changed:

now the red circle is [229 42 32]

green circle -> [24 241 42]

blue circle -> [29 26 230]

now, with this information (the input and the output RGB of the 3 circles) I want to repair the color of all of the image (the apples and the 3 circles).

so my input is:

(initial RGB of three circles, the RGB of these circles after I filmed)

and the output have to be a function: (R,G,B) -> (new R, new G, new B).

so the function have to repair all the RGB in the picture,

for the example I let before:

the red circle [229 42 32] will changed to his original [241 25 13]

the green circle [24 241 42] -> [12 239 41]

the blue circle[29 26 230] -> [35 28 237]

so, If I filmed and got one apple with RGB of [142, 124, 211], I want to run the function with his RGB and get the true color of this apple.

someone told me that I can use with the Least squares method.

You could do this:

In = [   229    24    29
          42   241    26
          32    42   230  ];

Out = [  241    12    35
          25   239    28
          13    41   237 ];

and then compute:

A = Out / In;   

A will be the desired lineary transformation from Input colors to desired output colors. This is just one model though and it's up to you to determine whether this is a particularly good one for color. I'm sure there's a lot of work on color calibration, but I'm not making any claims to know about this.

Also keep in mind that / is not normal division. It's a Matlab overload to basically do Out * inv(In) . It actually does a little more than this. See help mrdivide for more details.

Then to apply your new linear transformation, apply A to your color image. For a given input pixel inrbg = [ R ; G ; B ]; inrbg = [ R ; G ; B ]; you will compute

  outrgb = A * inrgb;

And you could appy this to the whole image.

Unfortunately, you will get some values outside of the allowable intensity ranges and you'll have to put them back. That's another indication that a pure linear model isn't necessarily a great one. At least this gives you somewhere to start.

One more thing, what I wrote above doesn't explicitly use Least Squares, but if you have more estimates for the color inputs and outputs such as

>> InN = [In randn(size(In))+In];  % just an example to get more columns, don't use this
>> InN

InN =

  229.0000   24.0000   29.0000  228.2382   25.2329   28.9302
   42.0000  241.0000   26.0000   41.3748  240.6159   26.5301
   32.0000   42.0000  230.0000   32.2829   42.0552  229.3372

>> OutN = [Out randn(size(Out))+Out]; % just an example to get more columns, don't use this
>> OutN

OutN =

  241.0000   12.0000   35.0000  241.1487   10.8441   33.8811
   25.0000  239.0000   28.0000   25.3679  240.0666   27.0684
   13.0000   41.0000  237.0000   12.1927   41.2091  236.9066

Then this A = OutN / InN also still works and guess what it uses to solve it? Effectively Least Squares.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM