%% Photo Reflection and Linear Algebra
% Reflect a photo and illustrate the change from left- to right-handedness

% Load an image into a Stack-of-Matrices, and view it
A0 = imread('left_hand_writing.JPG');
A  = imresize(A0,[400,400]);
AA = double(A);
figure; hold on; subplot(1,2,1);
imshow(A)

%% Learn about how MATLAB handles photos
% A is an array of 3 matrices, each of size r by c.  
% The entries in A are non-negative integers in the range [0,255] 
[r,c,s] = size(A)

%% Handedness is an orientation
% To change the orientation, compose with an orientation reversing transformation
I = eye(c); % the identity matrix
J(:,1:c) = I(:,c:-1:1); % a matrix that reflects the photo A
K(:,1:r) = I(:,r:-1:1); % a matrix that reflects the photo A

%% See an indentiy matrix and a reflection matrix
subplot(1,2,2);
	imshow(I); pause;
subplot(1,2,2);
	imshow(J); pause;

%% Reflect each sheet
% Technicality: MATLAB treats the reals and unsigned integers differently

%A*J;
%J*A;
%J*A*K
for i = 1:3
	B(:,:,i)=uint8(double(A(:,:,i))*J);
%	B(:,:,i)=uint8(K*double(A(:,:,i)));
%B(:,:,i)=uint8(K*double(A(:,:,i))*J);
end


%% Display the result
subplot(1,2,2);
	imshow(B)


