title: Image Deblurring by Frequency Domain Inverse Filter Design
body: <p>I have a task about using a Gaussian Filter to blur an image then using the corresponding inverse Gaussian Filter to deblur the blurred image. The detailed instructions are shown below:</p>
  <p>Apply 2D-DFT to the spatial domain Gaussian filter, resulting in a frequency domain
  Gaussian filter. Create a frequency domain inverse Gaussian filter by taking the
  reciprocal value of all frequency domain Gaussian filter coefficients. Apply inverse 2DDFT and take the real-parts to create a spatial domain inverse Gaussian filter (the
  imaginary parts are theoretically 0, but may not be completely 0 due to numerical errors).</p>
  <p>The size of the blurring filter is 21x21, and the size of the original image is 256x256. Here is my blurring code on Matlab.</p>
  <pre><code>Img = imread('text.tif');
  img = im2double(Img);
  gf = zeros(21);
  for i = 1:21
      for j = 1:21
          gf(i,j) = (1/(2*pi))*exp(-((i-10.5)^2+(j-10.5)^2)/2);
      end
  end
  Convig = conv2(img,gf);
  </code></pre>
  <p>The output image is shown below.
  <a href="https://i.stack.imgur.com/1HvYO.png" rel="nofollow noreferrer">Blurred Image</a></p>
  <p>Then following the instructions, my deblurring code is shown below:</p>
  <pre><code>dftgf =fft2(gf);
  idftgf = 1./dftgf;
  inverse = ifft2(idftgf);
  gf2 =real(inverse);
  Convig2 = conv2(Convig,gf2);
  </code></pre>
  <p>The result of blurring seems to be correct. But it is strange that the deblurring image is incorrect <a href="https://i.stack.imgur.com/EX1t2.png" rel="nofollow noreferrer">Deblurring Attempt</a>. Could someone help me with my code? Thanks in advance.</p>