I am currently working on a project where I have to reconstruct an Image from its gradient by solving a Poisson equation, which we solve in the Fourier domain.
The solution involves the product of the image's FT and that of the discrete derivation filter. In the Fourier domain, this is defined as the coordinate-wise product of the two.
I understand how the FT of an image is computed, however I have trouble understanding how I should compute that of a filter, as [0 -1 1]
for horizontal differences. Should I use the same formula as for images? This seems weird to me as I would keep only 2 components of my FT after having multiplied it with the image's FT.
To compute the convolution though the Fourier domain, one first pads the kernel with zeros to have the same size as the image, then computes the FFT of both the image and the padded kernel, and then multiplies those two frequency spectra. It is important that the origin of the kernel be put in the right place when padding. See this answer for details on how to do the padding right.
However, to compute derivatives you do not want to do it this way. Instead, use the Fourier property that the derivative in the spatial domain is a multiplication with jω.
The [1,0,-1]
filter (or [0,1,-1]
or whichever you want to use) is a discrete approximation to the derivative. If you go through the Fourier domain, you might as well compute the exact derivative.
For example, in MATLAB you would do:
a = imread('cameraman.tif');
A = fft2(a);
N = size(A,2); % we're computing the x-derivative here, that is dimension 2 in MATLAB
w = ifftshift((0:N-1)-floor(N/2)) * (pi / N);
B = A .* (1i * w); % for MATLAB R2016a and older, use bsxfun here
b = real(ifft2(B));