load colorRGB

i = 1:256;
iMonitorGamaR = (i/256).^(1/1.4870);
iMonitorGamaG = (i/256).^(1/1.6327);
iMonitorGamaB = (i/256).^(1/1.6565);

fidR = fopen('centerNoDifferencesR2.txt','w');
fidG = fopen('centerNoDifferencesG2.txt','w');
fidB = fopen('centerNoDifferencesB2.txt','w');

countBack = 0;
for backgroundWavelength = 565
%for backgroundWavelength = 430:15:730
indexBack = backgroundWavelength-430+1;
countBack = countBack + 1;

inputRGB(1) = 255*colorR(1,indexBack);
inputRGB(2) = 255*colorG(1,indexBack);
inputRGB(3) = 255*colorB(1,indexBack);

countTarget = 0;
%for targetWavelength = 485
for targetWavelength = 430+5:25:730
indexTarget = targetWavelength-430+1;
countTarget = countTarget + 1;

['Processing: ' num2str(backgroundWavelength) '-' num2str(targetWavelength)]

imageG = imread(['centerYesOutput/' num2str(backgroundWavelength) '-' num2str(targetWavelength) '.jpg']);

image(:,:,1) = iMonitorGamaR(double(imageG(:,:,1))+1);
image(:,:,2) = iMonitorGamaG(double(imageG(:,:,2))+1);
image(:,:,3) = iMonitorGamaB(double(imageG(:,:,3))+1);

[X map] = rgb2ind(image, 256);
imwrite(X, map, ['centerNoOutputG2/a-' num2str(backgroundWavelength) '-' num2str(targetWavelength) '.bmp'], 'bmp')

% Upper Left
upper = 1;
lower = 50;
left = 1;
right = 50;
avg1 = mean(mean(double(image(upper:1:lower,left:1:right,:))));
image(upper:1:lower,left:1:right,:) = 1;

% Upper Right
upper = 1;
lower = 50;
left = 1280-50;
right = 1280;
avg2 = mean(mean(double(image(upper:1:lower,left:1:right,:))));
image(upper:1:lower,left:1:right,:) = 1;

% Lower Left
upper = 1024-50;
lower = 1024;
left = 1;
right = 50;
avg3 = mean(mean(double(image(upper:1:lower,left:1:right,:))));
image(upper:1:lower,left:1:right,:) = 1;

% Lower Right
upper = 1024-50;
lower = 1024;
left = 1280-50;
right = 1280;
avg4 = mean(mean(double(image(upper:1:lower,left:1:right,:))));
image(upper:1:lower,left:1:right,:) = 1;

%imshow(image);

outputRGB(1) = mean([avg1(1,1,1), mean([avg2(1,1,1), avg3(1,1,1)])]);
outputRGB(2) = mean([avg1(1,1,2), mean([avg2(1,1,2), avg3(1,1,2)])]);
outputRGB(3) = mean([avg1(1,1,3), mean([avg2(1,1,3), avg3(1,1,3)])]);

%inputRGB
%outputRGB*255+1
%(outputRGB*255+1) - inputRGB

differences(countBack,countTarget,:) = (outputRGB*255+1) - inputRGB;

fprintf(fidR,'%f\t',differences(countBack,countTarget,1));
fprintf(fidG,'%f\t',differences(countBack,countTarget,2));
fprintf(fidB,'%f\t',differences(countBack,countTarget,3));

[X map] = rgb2ind(image, 256);
imwrite(X, map, ['centerNoOutputG2/b-' num2str(backgroundWavelength) '-' num2str(targetWavelength) '.bmp'], 'bmp')

end

fprintf(fidR,'\n');
fprintf(fidG,'\n');
fprintf(fidB,'\n');

end

save 'centerNoDifferences2.mat' differences

fclose('all');
