title: How to make a Gaussian filter in Matlab
body: <p>I have tried to make a Gaussian filter in Matlab without using <code>imfilter()</code> and <code>fspecial()</code>.
  I have tried this but result is not like the one I have with imfilter and fspecial.</p>
  
  <p>Here is my codes.</p>
  
  <pre><code>function Gaussian_filtered = Gauss(image_x, sigma)
  
  % for single axis
  % http://en.wikipedia.org/wiki/Gaussian_filter
  Gaussian_filtered = exp(-image_x^2/(2*sigma^2)) / (sigma*sqrt(2*pi)); 
  end
  </code></pre>
  
  <p>for 2D Gaussian, </p>
  
  <pre><code>function h =  Gaussian2D(hsize, sigma)
  
  n1 = hsize;
  n2 = hsize;
  
  for i = 1 : n2 
          for j = 1 : n1
          % size is 10;
          % -5&lt;center&lt;5 area is covered.
          c = [j-(n1+1)/2 i-(n2+1)/2]';                
          % A product of both axes is 2D Gaussian filtering
          h(i,j) = Gauss(c(1), sigma)*Gauss(c(2), sigma);        
          end
      end
  end
  </code></pre>
  
  <p>and the final one is</p>
  
  <pre><code>function Filtered = GaussianFilter(ImageData, hsize, sigma)
  
  %Get the result of Gaussian
  filter_ = Gaussian2D(hsize, sigma);
  
  %check image
  [r, c] = size(ImageData);
  Filtered = zeros(r, c);    
  
  for i=1:r
      for j=1:c
          for k=1:hsize
              for m=1:hsize
                      Filtered =  Filtered + ImageData(i,j).*filter_(k,m);    
              end
          end
      end
  end
  end
  </code></pre>
  
  <p>But the processed image is almost same as the input image. I wonder the last function <code>GaussianFiltered()</code> is problematic...</p>
  
  <p>Thanks.</p>