%% Down-sizing high resolution images
% Most likely, the images we upload to MATLAB are high-resolution photographs with hundreds of thousands of pixels.  We should compress the image down to a manageable size so our laptops can crunch the numbers more efficiently.  This code will do that for us.

%% Syntax (assuming M is the result of LoadPics, or similar)
% A = ResizeMatrix(M);

%% To use & edit this code, paste the following into MATLAB, hit return and save the file as SeeVector.m
% grabcode('http://euclid.nmu.edu/~joshthom/Teaching/MA211/ResizeMatrix.html');

%% The main function is called ResizeMatrix.
% It will resize each rgb-sheet of a color image, M, into a smaller image NewM
function NewM = ResizeMatrix(M,R,C);

%% Return the size (rows, collumns, sheets) of original
	[r,c,d] = size(M);

%% Set the size of new image 
	if nargin == 1;
		R = 30;
		C = 40;
	end

%% Loop throuh with some voo-doo and resize
	for i = 1:d	
		N = double(M(:,:,i));
		[r,c] = size(N);
		orgY = 1:r;
		orgX = 1:c;
		[orgX,orgY] = meshgrid(orgX ,orgY);
		newY = linspace(1,r,R);
		newX = linspace(1,c,C);
		[newX,newY] = meshgrid(newX,newY);
		NewM(:,:,i) = uint8(interp2(orgX,orgY,N,newX,newY));
	end
