% GET COLOR BALANCE
% get the intrinsic color balance of each light source
sun_white = double(imread('C:\Documents and Settings\Kim Shultz\My Documents\ee362\sun\white.jpg'))/255;
flour_white = double(imread('C:\Documents and Settings\Kim Shultz\My Documents\ee362\flourescent\white.jpg'))/255;
incan_white = double(imread('C:\Documents and Settings\Kim Shultz\My Documents\ee362\incandescent\white.jpg'))/255;
flash_white = double(imread('C:\Documents and Settings\Kim Shultz\My Documents\ee362\flash\white.jpg'))/255;
shad_white = double(imread('C:\Documents and Settings\Kim Shultz\My Documents\ee362\shadow\white.jpg'))/255;
image = sun_white;
% first, find the average RGB values
Rav = mean(image(:,:,1));
Rav = mean(Rav);
Gav = mean(image(:,:,2));
Gav = mean(Gav);
Bav = mean(image(:,:,3));
Bav = mean(Bav);
%scale av value so that max(Rav,Gav,Bav) = 1 (because image is white)
scale = 1/max([Rav Gav Bav]);
Rav = Rav*scale;
Gav = Gav*scale;
Bav = Bav*scale;
% save averages
sun_Rav = Rav;
sun_Gav = Gav;
sun_Bav = Bav;
image = flash_white;
% first, find the average RGB values
Rav = mean(image(:,:,1));
Rav = mean(Rav);
Gav = mean(image(:,:,2));
Gav = mean(Gav);
Bav = mean(image(:,:,3));
Bav = mean(Bav);
%scale av value so that max(Rav,Gav,Bav) = 1 (because image is white)
scale = 1/max([Rav Gav Bav]);
Rav = Rav*scale;
Gav = Gav*scale;
Bav = Bav*scale;
% save averages
flash_Rav = Rav;
flash_Gav = Gav;
flash_Bav = Bav;
image = incan_white;
% first, find the average RGB values
Rav = mean(image(:,:,1));
Rav = mean(Rav);
Gav = mean(image(:,:,2));
Gav = mean(Gav);
Bav = mean(image(:,:,3));
Bav = mean(Bav);
%scale av value so that max(Rav,Gav,Bav) = 1 (because image is white)
scale = 1/max([Rav Gav Bav]);
Rav = Rav*scale;
Gav = Gav*scale;
Bav = Bav*scale;
% save averages
incan_Rav = Rav;
incan_Gav = Gav;
incan_Bav = Bav;
image = shad_white;
% first, find the average RGB values
Rav = mean(image(:,:,1));
Rav = mean(Rav);
Gav = mean(image(:,:,2));
Gav = mean(Gav);
Bav = mean(image(:,:,3));
Bav = mean(Bav);
%scale av value so that max(Rav,Gav,Bav) = 1 (because image is white)
scale = 1/max([Rav Gav Bav]);
Rav = Rav*scale;
Gav = Gav*scale;
Bav = Bav*scale;
% save averages
shad_Rav = Rav;
shad_Gav = Gav;
shad_Bav = Bav;
image = flour_white;
% first, find the average RGB values
Rav = mean(image(:,:,1));
Rav = mean(Rav);
Gav = mean(image(:,:,2));
Gav = mean(Gav);
Bav = mean(image(:,:,3));
Bav = mean(Bav);
%scale av value so that max(Rav,Gav,Bav) = 1 (because image is white)
scale = 1/max([Rav Gav Bav]);
Rav = Rav*scale;
Gav = Gav*scale;
Bav = Bav*scale;
% save averages
flour_Rav = Rav;
flour_Gav = Gav;
flour_Bav = Bav;
% create an array with all the balancing values
balanceValues = [[sun_Rav shad_Rav flour_Rav incan_Rav flash_Rav]
[sun_Gav shad_Gav flour_Gav incan_Gav flash_Gav]
[sun_Bav shad_Bav flour_Bav incan_Bav flash_Bav ]];