% Get the snow image
input = imread('P2-crayons-raw.bmp');
imshow(input);
% Call myhisteq, display image and save
output = mydemosaic(input);

% Test output
figure;
imshow(output);

imwrite(output, 'skobov.demosaic.jpg');

% Sum of squared differences calculation
original = imread('P2-crayons.jpg');
M = size(output, 1);
N = size(output, 2);
error = zeros(M, N);

for row=1:M
   for col=1:N
      red_e = (output(M,N,1) - original(M,N,1))^2;
      green_e = (output(M,N,1) - original(M,N,1))^2;
      blue_e = (output(M,N,1) - original(M,N,1))^2;
      error(row,col) = red_e + green_e + blue_e;
   end
end

% Show calculated difference images
figure;
imshow(error);
imwrite(error, 'crayons.difference.jpg');


% Show matlab calculated difference between images
figure;
h = imshowpair(original, output);