function im1a = mytwist(im1)
% applies given twist to generate figure for colormatching paper
% to convert im1's colors into im2

     [h, w, nb] = size(im1);
     n = w*h;

     c1 = zeros(n, 3);
     c2 = zeros(n, 3);
     for b = 1:3,
	       c1(:,b) = double(reshape(im1(:,:,b), n, 1))/255;
%     c2(:,b) = double(reshape(im2(:,:,b), n, 1))/255;
     end

%     c1 = c1 .^ gamma;
im1a = im1;

twist = zeros(3, 3);
c1a = zeros(n, 3);

% NikonD300-wb2i1e3-raw.png
twist = [ 0.904760  0.373832  0.204103;
         -0.034788  0.989827  0.137957;
         -0.029664 -0.001621  0.999559];

% CanonEOS5D-wb1i2e3-raw.png
twist = [ 0.936820  0.331565  0.111501;
         -0.076041  0.987069  0.141115;
         -0.062749  0.117385  0.991102];

for b = 1:3,
    %twist(b, :) = (c1 \ c2(:, b))';
    c1a(:, b) = c1 * twist(b, :)';
    im1a(:, :, b) = reshape(uint8(255*c1a(:, b)), h, w);
end

twist
     
