%
% GrayWorldTest2.m
%
% Test GrayWorld algorithm for 2 real images
%
% Hui Li
% 3/7/2000
%

% First Image
im = imread('ST1GammaInv.jpg','jpg');
im = double(im)./256;
imshow(im);
		
% Read into RGB
r = im(:,:,1);
g = im(:,:,2);
b = im(:,:,3);

[GWr,GWg,GWb] = GrayWorldFun(r,g,b);

GWoutIm(:,:,1) = GWr;
GWoutIm(:,:,2) = GWg;
GWoutIm(:,:,3) = GWb;
imshow(GWoutIm);

imwrite(GWoutIm, './GWoutput/GWStanfordTower1.jpg', 'jpg');

avgIn1RGB = [mean(mean(r)) mean(mean(g)) mean(mean(b))];
avgGW1RGB = [mean(mean(GWr)) mean(mean(GWg)) mean(mean(GWb))];
avgIn1 = mean([mean(mean(r)) mean(mean(g)) mean(mean(b))]);
avgGW1 = mean([mean(mean(GWr)) mean(mean(GWg)) mean(mean(GWb))]);


% Second image
im = imread('ST2GammaInv.jpg','jpg');
im = double(im)./256;
imshow(im);
		
% Read into RGB
r = im(:,:,1);
g = im(:,:,2);
b = im(:,:,3);

[GWr,GWg,GWb] = GrayWorldFun(r,g,b);

GWoutIm(:,:,1) = GWr;
GWoutIm(:,:,2) = GWg;
GWoutIm(:,:,3) = GWb;
imshow(GWoutIm);

imwrite(GWoutIm, './GWoutput/GWStanfordTower2.jpg', 'jpg');

avgIn2RGB = [mean(mean(r)) mean(mean(g)) mean(mean(b))];
avgGW2RGB = [mean(mean(GWr)) mean(mean(GWg)) mean(mean(GWb))];
avgIn2 = mean([mean(mean(r)) mean(mean(g)) mean(mean(b))]);
avgGW2 = mean([mean(mean(GWr)) mean(mean(GWg)) mean(mean(GWb))]);
