%
% GrayWorldPlot.m
%
% Use the output of 100 image series to plot mean [R G B] value for GrayWorld Algorithm
%
% Hui Li
% 3/7/2000
%

backgroundCol = ['430' '445' '460' '475' '490' '505' '520' '535' '550' '565' '580' '595' '610' '625' '640' '655' '670' '685' '700' '715' '730'];
primeCol = ['435' '460' '485' '510' '535' '560' '585' '610' '635' '660' '685' '710'];

bg = 430:15:730;
pc = 435:25:710;

avgGWR = zeros(12,21);
avgGWG = zeros(12,21);
avgGWB = zeros(12,21);

for j = 1:12
	for i = 1:21
		bmin = (i-1)*3+1;
		bmax = i*3;
		pmin = (j-1)*3+1;
		pmax = j*3;
		GWoutputfn = strcat('./GWoutput/GWoutput',backgroundCol(bmin:bmax),'-',primeCol(pmin:pmax),'.bmp');

		[X,map] = imread(GWoutputfn,'bmp');
		
		% Read into RGB and compute mean
		Y = double(X)+1;
		[r,g,b] = ind2rgb(Y,map);

		avgGWR(j,i) = mean(mean(r));
		avgGWG(j,i) = mean(mean(g));
		avgGWB(j,i) = mean(mean(b));
		
	end
end


avgGW = (avgGWR + avgGWG + avgGWB)./3;
save('avg252GW.mat','avgGWR','avgGWG','avgGWB','avgGW');


% Plot results

load avg252GW.mat;

figure
mesh(bg,pc,avgGWR);
title('Mean Red Value of GrayWorld Output');
xlabel('Background Wavelength');
ylabel('Target Wavelength');
zlabel('R Values');

figure
mesh(bg,pc,avgGWG);
title('Mean Green Value of GrayWorld Output');
xlabel('Background Wavelength');
ylabel('Target Wavelength');
zlabel('G Values');

figure
mesh(bg,pc,avgGWB);
title('Mean Blue Value of GrayWorld Output');
xlabel('Background Wavelength');
ylabel('Target Wavelength');
zlabel('B Values');

figure
mesh(bg,pc,avgGW);
title('Mean Gray Value of GrayWorld Output');
xlabel('Background Wavelength');
ylabel('Target Wavelength');
zlabel('Gray Values');


