clear all;
close all;

gm_gray

% Get original image and forced Specular Reflection assumption image

% Get camera image
CameraGamma = 1.8004;
DisplayGamma = 2.7;
newImage = flipud(rot90(reshape(1:24,6,4)));

J=imread('IMAGES/gm_lgtson.bmp','bmp');
K=reindexImage(J);
K=scale(K,0,1,mmin(K),mmax(K));
Klinear = K.^CameraGamma;
K=K.^(CameraGamma/DisplayGamma);
figure
colormap(K); image(newImage);
title('Camera Image');

% Plot Y-component of camera image,original image,Specular
% reflection color-balanced image adn filtered image

KXYZ = inv(xyz2rgb)*Klinear';                   % camera luminance
macXYZ = inv(xyz2rgb)*GWmacbeth1';              % original luminance 
GWmacbethXYZ1 = inv(xyz2rgb)*macbethRGBCast';   % Cast luminance
GWmacbethXYZ2 = inv(xyz2rgb)*SRbalanced';       % SR balanced luminance


figure
plot(macXYZ(2,:),'r+-')
hold on
plot(KXYZ(2,:),'b*-')
hold on
plot(GWmacbethXYZ1(2,:),'go-')
hold on
plot(GWmacbethXYZ2(2,:),'ks-')
legend('original', 'camera','cast','SR output');
title('Luminance Comparison');


figure;
subplot(2,2,1)
plot(GWmacbeth1(:,1),'r+-');
hold on
plot(GWmacbeth1(:,2),'g+-');
hold on
plot(GWmacbeth1(:,3),'b+-');
hold off
title('RGB values for GW balanced Image');
  
subplot(2,2,2)  
plot(macbethRGBCast(:,1),'r+-');
hold on
plot(macbethRGBCast(:,2),'g+-');
hold on
plot(macbethRGBCast(:,3),'b+-');
hold off  
title('RGB values for cast Image');
    
subplot(2,2,3)
plot(SRbalanced(:,1),'r+-');
hold on
plot(SRbalanced(:,2),'g+-');
hold on
plot(SRbalanced(:,3),'b+-');
hold off
title('RGB values for SRA balanced Image');

subplot(2,2,4)
plot(K(:,1),'r+-')
hold on
plot(K(:,2),'g+-')
hold on
plot(K(:,3),'b+-')
hold off
legend('R','G','B');
title('RGB values for Camera Image');
  
