Reputation: 314
I'm working on some very simple image deconvolution for proof of concept.
The goal is to convolve an image with a kernel (I'm using a 5*5 gaussian matrix) and then deconvolve it in the fourier domain.
By taking the FFT of an both an image matrix and a filter kernel, element multiplying them together, and taking the iFFT of the result, I am able to achieve the same result as a sliding kernel convolution. To undo this convolution, I should be able to element divide the image's FFT and the filter's FFT.
However, when I try to implement this, I end up with a very strange texture thing. I know my methodology is right, but I cannot seem to find the bug in my code and it's driving me nuts.
# blur image
imblur = filters.convolve(im1, blurfilter)
# compute fft of kernel with padding
padfilfft = np.fft.fft2(blurfilter, s=im1.shape[:2], axes=(0,1))
# take fft of image
imfft = np.fft.fft2(imblur)
# element division
deconvolveimfft = np.divide(imfft, padfilfft)
deconvolveim = np.abs(np.fft.ifft2(deconvolveimfft))
Here's the output using plt.imshow():
And this is the original picture. I'm reading it in using misc.imread
with flattening:
For what it's worth, blurfilter
is defined as follows:
blurfilter = (1./273.) * np.array([[1,4,7,4,1],[4,16,26,16,4],[7,26,41,26,7],[4,16,26,16,4],[1,4,7,4,1]])
Upvotes: 4
Views: 1403
Reputation: 314
Ok, so I actually was able to figure it out. Turns out it was an "issue" with my kernel. I found that, in general, a gaussian kernel with sigma > 1 will yield this strange noise issue. As @MarkRansom pointed out in the comments, the fft from the filter becomes very close to zero. For some reason, there is much less noise amplification when we use kernels with σ<1.
Upvotes: 2