% Focus on the process of the Lumination.  Mainly
% L* of the Lab Space Data

load result;

%----------------------------------
% using the rgb definition for the encoding.
rgb2xyz = [0.5879 0.1792 0.1831; 0.2896 0.6058 0.1046; 0.0 0.06826 1.02];
white = [95 100 109];
midgrey = [0.5 0.5 0.5];
midtone = [0.5774 0.5774 0.5774];
red = [1 0 0];
green = [0 1 0];
blue = [ 0 0 1];

% some other surrounding color
yellow = [0.985 0.864 0.371];
purple = [0.528 0.432 0.562];
orange = [0.932 0.600 0.403];

colorset = [red;green;blue;yellow;orange;purple];
grayset = [midgrey;midtone];
xyzcolorset = rgb2xyz*colorset'*100;
xyzgrayset = rgb2xyz*grayset'*100;
labcolorset = xyz2lab(xyzcolorset',white);
labgrayset = xyz2lab(xyzgrayset',white);
chromcolorset = chrom(xyzcolorset);
chromgrayset = chrom(xyzgrayset);
%-------------------------------------

setcolor = ['r' 'g' 'b' 'y' 'c' 'm'];
colorstring = {'Red','Green','Blue','Yellow','Orange','Purple'};
company = {'PhotoNet','Ofoto','PhotoAccess','Shutterfly'};
xyztestimage = rgb2xyz*colorset'*100;
labtestimage = xyz2lab(xyztestimage',white);
for i=1:4
   for j=1:6
      labdata = squeeze(labresult(i,j,:,:));
      Lcollect(j,:) = labdata(:,1)';
   end
   ref = labcolorset(:,1);
   companyloc = [1:6];
   companyloc = repmat(companyloc',1,801);
   figure
   for k=1:6
      hold on
      plot(companyloc(k,:),Lcollect(k,:),[setcolor(k) '.']);
      plot(companyloc(k,1),labtestimage(k,1),'k*');
      %subplot(3,2,k);
      %plot([0:800]/100,Lcollect(k,:),[setcolor(k) '-']);  
      %ylabel(['L* of ' colorstring{k}]);
   end
   axis([0 7 0 8]);
   title(['Lumination L* variation across horizontal Direction from ' company{i}]);
	xlabel('1->red, 2->blue, 3->green, 4->yellow, 5->orange, 6->purple');
end

% Remember that RGB to XYZ transform assumes that RGB is in counts, instead of
% 0 to 1
sinline = 0.9+0.1*sin(2*pi*[0:801-1]/120);
figure
for i=1:6
   xyzorigtemp = rgb2xyz*(colorset(i,:)'*sinline)*100;
   laborigtemp = xyz2lab(xyzorigtemp',white);
   subplot(3,2,i);
   plot([0:800]/100,laborigtemp(:,1),[setcolor(i) '-']);  
   ylabel(['L* of ' colorstring{k}]);
end 
gtext(['Lumination L* variation across horizontal Direction of Test Images']);
gtext('Horizontal Axis Means Hundreds of Pixels');

%--------------------------
%Process Gray Patches

% First, get out the mean value RGB of the patches
setcolor = ['r' 'g' 'b' 'y' 'c' 'm'];
colorstring = {'Red','Green','Blue','Yellow','Orange','Purple'};
company = {'PhotoNet','Ofoto','PhotoAccess','Shutterfly'};
graymean = grayresult(:,:,[1:3 7:9 13:15 19:21]);
grayreshape = reshape(graymean,4,6,3,4);
colorloc = [1:6];
colorlocmat = repmat(colorloc',1,4);
for i=1:4
   figure
   for j=1:6
      hold on
      onegrayxyz = rgb2xyz*squeeze(grayreshape(i,j,:,:))*100/255;
      grayxyz(i,j,:,:) = onegrayxyz;
      onegraylab = xyz2lab(onegrayxyz',white);
      graylab(i,j,:,:) = onegraylab;
      plot(colorlocmat(j,:),log10(onegraylab(:,1)),[setcolor(j) 'o']);
      plot(colorlocmat(j,1:2),log10(labgrayset(:,1)),'k*');
   end
   title(['Luminance Measurement of the Gray Patches from ' company{i}]);
   xlabel('1->red, 2->blue, 3->green, 4->yellow, 5->orange, 6->purple');
   ylabel('Log10 of the Luminance Value, L*');
   axis([0 7 -1 2]);
end

   