%
% function [T, error] = asymmetricMatching(colors1, colors2)
%
% figure out the linear transformation between any pair of Macbeth colors
% make sure the colors are already inverse gamma corrected
%
% Input: colors1, colors2: two 3xN matrices that we are trying to match
%
% Return: T : the best 3x3 matrices so that colors2 = T*colors1
%         error : the error is the average error per pixel per color channel
%                 so it's between 0 and 255
%

function [T, error] = asymmetricMatching(colors1, colors2)

[row1, col1] = size(colors1);
[row2, col2] = size(colors2);

if( (row1!=3) | (row2!=3) )
 error('color matrices must have 3 rows');
end

if( col1 != col2 )
 error('color matrices must have the same number of columns');
end

 T = colors2*pinv(colors1);
 estimatedColors2 = T*colors1;
 
 errorColors = colors2 - estimatedColors2;
 
 error = sqrt(sum(sum((errorColors.^2)))/(row1*col1));

