%% The basic linear algebra of images
%
% Performing basic matrix and vector calculations on digital photographs.

%% Compute the pairwise angle between each person in MA211.
	% Add a line that computes the angle to the ClassDistance script.

%% Show the effect of scalar multiplication on images
	% Load a photo of your choice and display the effect of scalar multiplication on it.
	A = rand(200,200);
	subplot(1,2,1); hold on;
	title('Standard Image');
	imshow(A);
	subplot(1,2,2); hold on;
	MyScalar = 2;
	imshow(MyScalar*A);
	title(['After scalar multiplication by ',num2str(MyScalar)]);

%% Measuring similarity of photos via Euclidean distance.
%  It is clear that Euclidean distance is not the perfect way to measure similarities
%  digital images.  A perfect measure simply doesn't exist (thankfully).  Nevertheless,
%  it is a natural starting point for basis image processing.  In the exercises below,
%  you are to use the Euclidean distance measure as a way to determine when two images
%  are similar.

%% Who is "way out there"?
%  On our first exam we proved
%% 
% $$(A^T A)_{ii} = ||A_i||^2.$$

% Use the fact above to compute the norms of each picture of our class image library.  
% Display the images of smallest and largest norms.  Based on your answers, 
% how does the brightness affect the norm of an image?

%% Find and display the photos of the two people whose images are the most similar.

% Here, you should use the commands (scripts) ClassDistance and FindNeighbors.m

%% Find and display the photos of the two people whose images are most dissimilar.

% Again, you should use the commands (scripts) ClassDistance and FindNeighbors.m

%% Show the effect of vector addition on vectorized images.

% Load two or more vectors, add them, and display the results.

%% Produce a linear combination of images
% After running ClassDistance, compute a non-trivial linear combination of multiple photographs.  

% IMPORTANT: Multiplication between a matrix and a vector produces a linear combination
% of the columns of the matrix, whose coefficients are the elements of the vector.
% Choose small (random, perhaps) coefficients so your linear combination remains visable.
NumVex = 3;
M = reshape(1:12,4,NumVex)
C = [100 200 0]'
C = C/norm(C)

V=M*C

%% Changes in contrast & brightness are linear combinations 

figure;
for i = 0:.1:2;
for j = 1:20:200;
imshow(reshape(uint8(i*PicVex(:,n) + j*ones(size(PicVex(:,n)))),r,c,3))
drawnow; pause(.1); end
end
	
%% Analyze your calculations.  
	% Describe what you learned during this project.  Specifically, elaborate on 
	% how this project changed your perception of the concepts of  linear combinations
	% spanning and linear independence.  Is it likely that two photographs of the 
	% same person under varying light conditions are linearly independent?  Is it
	% likely that two different people will be linearly independent?  

%% Construct arbitrary elements of the class subspace
	% Using rondomly selected coefficients, construct and display randomly selected
	% vectors from the subspace spanned by n linearly independent vector-photos.  Can
	% you "see" the basis elements.

	% Must work on scaling for the above

	% Develop this project with rank, subspace in mind, as well as lighting subspace
	% and different metrics.

%% Compute the "L-1" distance between each person in MA211.
	% Edit/Add to the code below
	a = 1:10;
	b = 1:2:20;
	L1_Dist = sum(abs(a-b));
	
