%% Loading data
pre = load_dds('pre_cc.dds');
post = load_dds('post_cc.dds');

%% Loading data type9
pre = compose_hud_all2('D:/EDDebugging/hud_images', 'no_hud.dds', 896, 926);
post = load_dds('D:/EDDebugging/hud_images/after_pp.dds');


%% Solving the problem
pre_sat = min(pre, repmat(1, size(pre)));
%pre = rgb2hsv(pre_sat);
%post = rgb2hsv(post);
pre_r = pre_sat(:,:,1);
pre_g = pre_sat(:,:,2);
pre_b = pre_sat(:,:,3);
post_r = post(:,:,1);
post_g = post(:,:,2);
post_b = post(:,:,3);

A = [pre_r(:) pre_g(:) pre_b(:) ones(prod(size(pre_r)),1)];
%A = extend_ls_mat(A, 1);
r = A\post_r(:);
g = A\post_g(:);
b = A\post_b(:);
mat = [r g b];

c = [reshape(pre, prod(size(pre_r)), []) ones(prod(size(pre_r)), 1)];
%c = extend_ls_mat(c, 1);
test_img = reshape(c * mat, size(pre));

imshow(test_img)