0

I have captured this image with motion blur with my phone camera and want to deblur it. enter image description here

I modeled the blur PSF as a line with length L and angle phi, and calculated those values. I constructed the PSF as a zeros matrix and a line at the center with the length and angle calculated previously. The values of the line are 1/L, so the total sum of values from the matrix is 1. I assigned this matrix to the variable "h".

enter image description here

Now I want to use this 256x256 PSF to deconvolve the blurred 256x256 image. I have researched and found expressions to determine an approximation of the Fourier transform of the deblurred image, but they use artificial blurred images, for which they know the variance of the noise signal and can use the Wiener Filter function from MATLAB. A paper proposes this expression:

enter image description here

which gives me results like the following:

enter image description here

This is the snippet of the code I'm using for the deconvolution:

imgdouble = double(imgrec)/255;
H = fft2(h);    % PSF
Hc = conj(H);
I = fft2(imgdouble);
Fhat = I.*(Hc./(abs(H).^2+1/256));
figure, imshow(ifft2(Fhat))
GanimEdes
  • 23
  • 5
  • Two things: use `fft2(ifftshift(h))` to avoid shifting the output by half an image; and play around with the value of K until you get acceptable results. If K is too small, you’ll get a very noisy output, if it is too large, you will see a blurry output. Optimal is somewhere in between. – Cris Luengo Jul 11 '21 at 00:38
  • I forgot to mention that "h" is the PSF in the pixel domain and its the matrix with the line in the middle – GanimEdes Jul 11 '21 at 14:12
  • Yes, my comment made that assumption. – Cris Luengo Jul 11 '21 at 14:17
  • Wouldn't it be fftshift(ifft2(h)) because h is in the pixel domain? H is the Fourier transform of this PSF – GanimEdes Jul 11 '21 at 14:20
  • No. `h` is defined with the origin in the middle. `ifftshift(h)` is the kernel with the origin in the top-left pixel, where the FFT assumes the origin is. This removes the shift you’re seeing in your result. Note you don’t need to shift the result of the FFT, nor the image itself. Only for the kernel does it matter in this case where the origin is. – Cris Luengo Jul 11 '21 at 14:22
  • Is something wrong with the deconvolution method in the code? I've corrected the origin of the PSF, and the best result I got while trying different values of K was the same original blurred image, but darker – GanimEdes Jul 11 '21 at 14:50
  • Code seems fine. You need to guess the `h` very precisely, if you’re wrong about your assumptions it won’t work. There are more complex deconvolution algorithms that jointly estimate the deconvolved image and the kernel. You might want to look into one of those instead. – Cris Luengo Jul 11 '21 at 15:20

0 Answers0