function myImg = loadImage(pic, gry, flag)
% This function loads the file "pic" (should be a jpeg).
% If gry = 0, it's loaded as a color picture.
% If gry = 1, it's turned into a grayscale image.
% flag determines whether the image is displayed.
% flag = 0 not shown / flag = 1 shown

myImg = imread(pic);

if gry == 1 
    tmp = .2989*myImg(:,:,1) + .5870*myImg(:,:,2) + .1140*myImg(:,:,3);
    myImg = tmp;
end;

if flag == 1
    figure; 
    if gry == 1
            colormap(gray(256)); 
    end;
    %image(myImg);
    imshow(myImg);
end;

% convert to double so the image can be manipulated.
myImg = double(myImg);




