Reputation: 2266
I have a 24 block color card and I'm trying to estimate a color correction matrix to the captured images with the said color card. I have manually estimated a CCM
using the least squares
method and it's not producing desirable results. Some images get a weird shade after applying CCM
.
I have double checked my code but couldn't find any glitches. I'm looking for any opencv/matlab based or any open source implementations where I can provide the captured color values and the actual color values and it can calculate and apply CCM for me to make sure if it's my implementation which has problems or the least squares method is not very effective.
Note : I'm not applying any linearization to the image before applying CCM. Please suggest any resources where this can be quickly tested.
PS : Following is the MATLAB code I'm using to estimate and apply the Color Correction Matrix (CCM)
% calc 3x3 correction matrix
ccm = MactAll * MrawAll' * inv(MrawAll * MrawAll') % MactAll is the 3x24 matirx of actual color card values and MrawAll is the 3x24 matrix of captured color card values
here's how I'm applying the CCM to the image
[my, mx, mc] = size(imageRGB); % rows, columns, colors (3) %
imageRGB = reshape(imageRGB,my*mx,mc);
correctedRGB = imageRGB*ccm;
correctedRGB = min(correctedRGB,1); correctedRGB = max(correctedRGB,0); % Place limits on output.
correctedRGB = reshape(correctedRGB, my, mx, mc);
correctedRGB = uint8(correctedRGB*255);
Here are my results:
Corrected Image
Upvotes: 2
Views: 8897
Reputation: 103
The RGB samples used in the optimization should be linear. Undo gamma correction first by calling rgb2lin
on the image.
You will also need to apply the CCM on linear RGB values. So undo the gamma correction in your image with rgb2lin
, apply the CCM, and then re-apply gamma correction with lin2rgb
.
Upvotes: 0
Reputation: 718
color correction model you are using is well described here:
This can also be done in c++ opencv. You have to determine equation:
[p1' p2' ... pn' ] = M * [ p1 p2 ... pn]
P' = M * P
Where p1',...pn' are desired values (better if in XYZ color space), p1, ... pn are real values detected and M is 3x3 transformation matrix.
You could solve that system as follows:
M = P * P'.inv(CV_SVD)
Upvotes: 4