How to Linearise an Input Image before applying Color Correction? I'm doing color correction on Raw images taken from Camera directly. I want to make my Camera reproduce same colors as my Target camera. 

Here are the steps I'm following:


Take Target Color values by Capturing a Macbeth Color chart by using Target Camera &amp; Take set of 24 Color Palette's.
Take the Input Color Values by Capturing the same Macbeth Color chart by using Reference Camera &amp; Take set of 24 Color Palette's.


Now if i Compute Color correction directly at this stage, all the White colors are appearing Rose or Not correct.

So I'm applying Gamma correction as follows:


Split the Three channels. For each Color find the Gamma for that color palette by using this formula.

float Gamma_R = log10(Target_R/255.0))/(log10(Input_R/255.0);


Error Cases:1

If the Input_Channel Value == 255 make it as 254

If the Input_Channel Value == 0 make it as 1 

If gamma_Channel > 3 or gamma_Channel &lt; 0.2 make gamma_Channel as 1.


Average the Values of Gamma_R for all 24 colors &amp; make this as a
gamma of that channel.
Apply Gamma for Each channel using the Gamma computed for Each channel using the formula.

Corrected_R = 255 * (Input_R/255)^(1/Gamma_R)


My Problem:


How to make sure the Gamma Values that I've computed are correct at this stage? Also correct me if I'm doing it wrong.
What to do when the Following Error case: 1 happens?
After applying Gamma correction &amp; Color Correction using 3x3 Matrix (Assume I'm doing that correctly) still the colors are not reproduced correctly.
If i encode the gamma by using same Gamma Values from Previous stage using this formula, again the Colors are not reproduced correctly.

Corrected_R = 255 * (Input_R/255)^(Gamma_R)
So do i need to compute the Gamma again from the Color corrected output?


Any suggestion or References is greatly appreciated!
Your linearization gamma calculation does not take into account the correction matrix.

You could do a combined numerical optimization of the pre-correction-matrix gamma adjustment, the correction matrix, and the post-correction-matrix gamma adjustment, preferably using a colorimetric error metric. There are 11 variables to optimize (or up to 14 if you wand to add constant terms). That's doable without too much work if you don't need to repeat this very often. I have a C++ Differential Evolution optimization library here that should be able to handle it: http://yehar.com/blog/?p=643