
  % ------------------------------
  %
  % blurring a gray-scale image with a Gaussian
  
  % load image
  im=imread('fireplace.bmp');
  imshow(im)
  
  % convert to gray image
  imdb = double(im);
  gr = ((imdb(:,:,1).^2 + imdb(:,:,2).^2 + imdb(:,:,3).^2) / 3).^0.5;
  imshow(uint8(gr))

  mesh(gr); view(2); colormap(gray)
  

  % convolve gray image with Gaussian
  l = -10:10;
  x = exp(-0.01 * l.^2);
  H = x' * x;
  H = H ./ sum(sum(H));
  blurr = conv2(gr, H, 'same');
  imshow(uint8(blurr))

  
  % ------------------------------
  %
  % same with image toolbox
  
  
  % load image
  im = imread('fireplace.bmp');
  imshow(im)
  
  % convert to gray image
  gr = rgb2gray(im);
  imshow(gr)
  
  % convolve gray image with Gaussian
  H = fspecial('gaussian', 20, 20);
  blurr = imfilter(gr, H,'replicate');
  imshow(blurr)
  

  % convolve color image with Gaussian
  H = fspecial('gaussian', 20, 20);
  blurr = imfilter(im, H,'replicate');
  imshow(blurr)
  

  
