%% Scales an image by a user determined amount. Assumes the image is grayscale.
%% If the scale is greater than one, holes will be created. Scale values that 
%% are less than or equal to zero will make the image a projection of the image
%% onto the opposite axis.

%% Colton Watson
%% Math 2270
%% Last updated: May 6, 2018

function [out_image] = math_scale(in_image, horizontal_scale, vertical_scale)
   
  % Get the size of the in image
  [in_rows, in_cols] = size(in_image);
  
  % Calculate the size of the out image
  num_out_rows = ceil(in_rows * vertical_scale);
  num_out_cols = ceil(in_cols * horizontal_scale); 
 
  out_image = zeros(num_out_rows, num_out_cols);
  
  % Create the transformation matrix
  T_matrix =  [horizontal_scale, 0; 0, vertical_scale];
  
  % Go through each pixel, multiply it by the tranformation matrix to find where
  % in the scaled image the pixel will go. 
  for rows = 1:in_rows
    for cols = 1:in_cols
      out_pixel = (T_matrix * [cols; rows]);
            
      out_row = (round(out_pixel(2)));
      out_col = (round(out_pixel(1)));
      
      if (out_col >= 1 && out_row >= 1)
        out_image(out_row,out_col) = in_image(rows,cols);
      endif  
    endfor
  endfor
endfunction