3

to practice Wiener deconvolution, I'm trying to perform a simple deconvolution:

def div(img1 ,img2):
  res = np.zeros(img2.shape, dtype = 'complex_')
  for i in range (img2.shape[0]):
    for j  in range (img2.shape[0]):
      if (np.abs(img2[i][j]) > 0.001):
        res[i][j] = 1 / (img2[i][j])
      else:
        res[i][j] = 0.001
  return res

filtre = np.asarray([[1,1,1],
                     [1,1,1],
                     [1,1,1]]) * 1/9
filtre_freq = fft2(filtre)

v = signal.convolve(img, filtre)
F = div(1,(filtre_freq))
f = ifft2(F)

res = signal.convolve(v, f)

I am trying to compute the inverse filter in the frequency domain, pass it to the spatial domain and do the convolution with the inverse filter. On paper it's pretty simple, even if I have to manage the divisions by 0 without really knowing how to do it. But my results seem really inconsistent: enter image description here

If anyone can enlighten me on this ... Thanks in advance and have a great evening.

Nicolas
  • 51
  • 2
  • 1
    When you do `filtre_freq = fft2(filtre)`, you need to pad the filter to the size of your image first. Also, you need to do the inverse filtering in the Fourier domain: `ifft2 (fft(img) / fft(filter))`. This only works if you do the padding correctly, see here: https://stackoverflow.com/questions/54877892/convolving-image-with-kernel-in-fourier-domain/54977551#54977551 – Cris Luengo May 19 '22 at 22:55

0 Answers0