function [dataR, dataG, dataB] = processLabData(inFile)

% Usage: [R G B] = processLabData(fileName)
%
% Reads in a gamma-corrected tiff test image and extracts three
% column vectors of RGB data.
% The white regions in the image displayed at the end of the
% function's execution represent the regions where samples 
% were actually taken.
%
% KLY 98

[r g b] = tiffread(inFile);

windowSize = 20;
totalPixels = windowSize.^2;

windowSize = windowSize./2;

labdataR = zeros(4,6);
labdataG = zeros(4,6);
labdataB = zeros(4,6);

for i=1:4
  for j=1:6
    
    y = 125 + (i-1)*85;
    x = 97 + (j-1)*87;
    
    windowR = r(y-windowSize:y+windowSize,x-windowSize:x+windowSize);
    r(y-windowSize:y+windowSize,x-windowSize:x+windowSize) = 1;
    labdataR(i,j) = sum(sum(windowR))/totalPixels;
    
    windowG = g(y-windowSize:y+windowSize,x-windowSize:x+windowSize);
    g(y-windowSize:y+windowSize,x-windowSize:x+windowSize) = 1;
    labdataG(i,j) = sum(sum(windowG))/totalPixels;
    
    windowB = b(y-windowSize:y+windowSize,x-windowSize:x+windowSize);
    b(y-windowSize:y+windowSize,x-windowSize:x+windowSize) = 1;
    labdataB(i,j) = sum(sum(windowB))/totalPixels;
  
  end
end

figure
imshow(r,g,b)
title(['Sampled Regions (' inFile ')'])

% Display sampled data

dataR = reshape(labdataR,1,24);
dataG = reshape(labdataG,1,24);
dataB = reshape(labdataB,1,24);

figure
image(reshape(1:24,4,6))
colormap([dataR' dataG' dataB'])
title(['Sampled Data (' inFile ')'])
axis off






