title: Filtering an image in the DFT domain in matlab
body: <p>I want to apply the following filter to an image:</p>
  
  <pre><code>h = [1/4 1/16 1/4; 
       1/16 1/8 1/16; 
       1/4 1/16 1/4;]
  </code></pre>
  
  <p>I follow the steps bellow but i don't get the correct result. Can anyone help me? I can't find what is wrong with my steps. Here is the code:</p>
  
  <pre><code>I = imread('cameraman512.jpg');
  h = [1/4 1/16 1/4; 1/16 1/8 1/16; 1/4 1/16 1/4;]
  
  %padding image
  Ip = padarray(I,[512 512],'post');
  figure();
  imshow(Ip);
  
  %padding filter
  Hp = padarray(h,[512 512],'post');
  figure();
  imshow(Hp);
  
  %image fourier
  dftI = fft2(I);
  figure();
  imshow(dftI);
  
  % filter fourier
  dftH = fft2(H);
  figure();
  imshow(dftH);
  
  %shifting image and filter
  I = fftshift(Ip);
  figure();
  imshow(I,[]);
  
   H = fftshift(Hp);
   figure();
   imshow(H,[]);
  
  G = dftI.*dftH;
  figure();
  imshow(G);
  
  g=real(ifft2(G));
  figure();
  imshow(G);
  </code></pre>