function B = blur(pic, gry, flag)
% Blurs "pic" (a jpeg) and returns the blurred image.
% The image is converted to grayscale if gry = 1 and 
% the image is displayed if flag = 1.

% Load up the picture. A is a m by n matrix if grayscale
% and an m by n by 3 tensor if in color (think 3 matrices
% stacked on top of each other -- one each for RGB values.
A = loadImage(pic, gry, 0);

if gry == 0  % Color
    % Blur Red, Greens, and then Blues.
    B(:,:,1) = applyGaussianPSF(0.1, A(:,:,1), 1);
    B(:,:,2) = applyGaussianPSF(0.1, A(:,:,2), 1);
    B(:,:,3) = applyGaussianPSF(0.1, A(:,:,3), 1);
else % Grayscale
    B = applyGaussianPSF(0.1, A, 1);
end;

if flag == 1  % Display the image
    figure; 
    if gry == 1
        colormap(gray(256)); 
        
        % rescale to make image show up.
        x = max([max(max(B)),0.000001]);
        scaleB = (1/x)*B;
    else 
        % rescale to make image show up.
        x = max([max(max(max(B))),0.000001]);
        scaleB = (1/x)*B;
    end;
    %image(myImg);
    imshow(scaleB);
end;
