% In exam key image, 
% try to tell green text
% from black text

% This is the version we started with.
% See the ...inClass.m version for a cleaned-up 
% summary of what we did

%% Load image and select green text
I = imread('ExamKey.jpg');
% imshow(I)
% shg
% % (zoom in)
% p = ginput
p = [615        1085];
jrange = p(1)-10:p(1)+10;
irange = p(2)-10:p(2)+10;

imshow(I(irange,jrange,:))
shg
%% Plot color values of green text windo
% in RGB space
Ismall = I(irange,jrange,:);
red = Ismall(:,:,1);
green = Ismall(:,:,2);
blue = Ismall(:,:,3);
red = red(:);
green = green(:);
blue = blue(:);
plot3(red,green,blue,'g.');
xlabel('red');
ylabel('green');
zlabel('blue')
shg
%% select black text
% imshow(I)
% shg
% % zoom in
% ginput
% blackPoint = ans;
% blackPoint = round(blackPoint)
blackPoint = [337   947];
blackJRange = blackPoint(1)+(-10:10);
blackIRange = blackPoint(2)+(-10:10);
Iblack = I(blackIRange,blackJRange,:);
imshow(Iblack)
shg
%% Plot color values of black text image
redBlack = Iblack(:,:,1);
greenBlack = Iblack(:,:,2);
blueBlack = Iblack(:,:,3);
redBlack = redBlack(:);
greenBlack = greenBlack(:);
blueBlack = blueBlack(:);
plot3(redBlack,greenBlack,blueBlack,'k.');
hold off
shg
xlabel('red');
ylabel('green');
zlabel('blue')
%% Plot the two samples together
clf
plot3(red,green,blue,'g.');
hold on
plot3(redBlack,greenBlack,blueBlack,'k.');
hold off
shg
xlabel('red');
ylabel('green');
zlabel('blue')

