%
% GrayWorldTest1.m
%
% Use 100 image series to test 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'];

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

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

		%rgb = [r,g,b];
		%imshow(rgb,map);
		
		[GWr,GWg,GWb] = GrayWorldFun(r,g,b);

		GWoutIm(:,:,1) = GWr;
		GWoutIm(:,:,2) = GWg;
		GWoutIm(:,:,3) = GWb;
		
		[GWoutInd, mapOut] = rgb2ind(GWoutIm,256);

		outputfn = strcat('./GWoutput/GWoutput',backgroundCol(bmin:bmax),'-',primeCol(pmin:pmax),'.bmp');
		
		imwrite(GWoutInd, mapOut, outputfn, 'bmp');
		
	end
	
end


