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

%% Begin with command grabcode
%  This will create of copy of this code in your editor window.
%  Comment out (put a % in front of) the line below after you get the starter code. 

%grabcode('http://euclid.nmu.edu/~joshthom/Teaching/MA211/Homework1.html');

%% The angle between photographs.
%  1. Compute the angle between each pair of people in MA211.
    
% come back and uncomment this at end to produce final version:
% ClassDistance;

    % Made the following changes to FindNeighbors, and saved it as
    % FindAngleNeighbors:
    	% Replace this :: V = DistanceMatrix(row,:);
        % With this :: V = AngleMatrix(row,:);
    
FindAngleNeighbors

% %  2. Return a list of whose direction is nearest to whose.
% %  HINT: In ClassDistance, save the angle as AngleMatrix.
% %  HINT: In FindNearestNeighbor, change DistanceMatrix to AnleMatrix. 
% %  Change the "is closest to Person" line to "points in the same general direction as"
% 
% %% 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 edit the commands (scripts) ClassDistance and FindNearestNeighbor.m
% %  NOTE: You are to produce the numbers and photos of TWO people only.
% 
% %% Find and display the photos of the two people whose images are most dissimilar.
% %  Again, you should use the commands (scripts) ClassDistance and FindNearestNeighbor.m
% %  NOTE: You are to produce the numbers and photos of TWO people only.
% 
% %% Show the effect of vector addition on vectorized images.
% %  Load two or more vector-images, add them, and display the results.
% 
% %% Produce a linear combination of images
% %  Compute a non-trivial (coefficients not equal to 1) 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 
% 
P = ceil(23*rand(1));
figure;
for i = 1 %0:.1:2;
for j = 1:20:200;
imshow(reshape(uint8(i*PicVex(:,P) + j*ones(size(PicVex(:,P)))),r,c,3))
drawnow; pause; end
end
% 	
% 
% %% Compute the "ell-one" distance between each person in MA211.
% %  1. Replace the following line in ClassDistance:
% 
% DistanceMatrix(p,q) = norm(PicVex(:,p)-PicVex(:,q));
% 
% % with this line
% 
% DistanceMatrix_L1(p,q) = sum(abs(PicVex(:,p)-PicVex(:,q)));
% 
% % 1. On paper, show by example how these two distances are different.
% % 2. Do you get different neighbors under this distance measure?
%   
% %% 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?  
% 
% 
