% color2gray.m
% Takes in a color image (usually in JPG data format) and returns grayscale
% value.
% Probably not the most efficient way to do this, but I am just a young
% padouin in the world of Matlab

function grayscale = color2shadow(color_image);

image_dimensions = size(color_image);
image_height = image_dimensions(1);
image_width = image_dimensions(2);
image_colorspace = image_dimensions(3);

red_channel = color_image(1:image_height,1:image_width,1);
blue_channel = color_image(1:image_height,1:image_width,2);
green_channel = color_image(1:image_height,1:image_width,3);

intensities = red_channel/3 + blue_channel/3 + green_channel/3;

grayscale = zeros(image_height,image_width,image_colorspace);

for i = 1:image_height,
    for j = 1:image_width,
        grayscale(i,j,1) = intensities(i,j);
        grayscale(i,j,2) = intensities(i,j);
        grayscale(i,j,3) = intensities(i,j);
    end
end

% Adjust intensities for imshow grayscale range of [0,1]
grayscale = grayscale/256;