Hi, My problem is the following: Given a integer N, I need to generate a NxN kernel that approximates an arbitrary frequency filter. So I can use the (small) kernel to filter the image in spatial domain with convolution operations. For example I use the lowpass filter: (lowLv-hiLv) * e^ [-(f/Ft)^2] + hiLv where f is the euclidean distance between center and a "pixel" in frequency domain, Ft is the cutoff freq and lowLv and hiLv are multiplicative coefficients for low and hi frequencies. I hope that this filter is correct. Despite this fact, my teacher suggest me to take the inverse FFT of the filter to find out the kernel... but how? I try to find answers searching with Google and reading the book "Digital Image Processing" but I don't find what I need. Please help me. Best regards.
Help needed - compute convolution kernel from a frequency filter
Started by ●March 24, 2007
Reply by ●March 24, 20072007-03-24
Hi, If you have a matrix representing the response of the filter in the frequency domain, then you can invoke the command ifft2 (2D inverse FFT) in matlab to get the time domain kernel. Now the important thing is to verify that your frequency filter has the conjugate symmetry, so that the ifft2 will give you a real kernel. On 24 mar, 20:39, "boiacan" <boia...@gmail.com> wrote:> Hi, > My problem is the following: > Given a integer N, I need to generate a NxN kernel that approximates an > arbitrary frequency filter. So I can use the (small) kernel to filter the > image in spatial domain with convolution operations. > For example I use the lowpass filter: > > (lowLv-hiLv) * e^ [-(f/Ft)^2] + hiLv > > where f is the euclidean distance between center and a "pixel" in > frequency domain, Ft is the cutoff freq and lowLv and hiLv are > multiplicative coefficients for low and hi frequencies. > > I hope that this filter is correct. Despite this fact, my teacher suggest > me to take the inverse FFT of the filter to find out the kernel... but > how? > > I try to find answers searching with Google and reading the book "Digital > Image Processing" but I don't find what I need. > > Please help me. Best regards.
Reply by ●March 24, 20072007-03-24
>Hi, > >If you have a matrix representing the response of the filter in the >frequency domain, >then you can invoke the command ifft2 (2D inverse FFT) in matlab to >get the time domain kernel. >Now the important thing is to verify that your frequency filter has >the conjugate symmetry, >so that the ifft2 will give you a real kernel.Thanks for your answer but I'm not sure to understand. I'll try to give you more details. I've to do the whole thing in C++. I've no matrix representing the response of the filter (I've just the filter function) and I can't use external libraries for FFT (for example FFTW) so give a simple 1D FFT algorithm I can compute the inverse (or forward) transform for rows and cols in the usual way. But the tricky part (for me :-D) is to set up an array of data (that is a matrix in 2D) that represents the frequency filter and then to do reverse Fourier transform this data and scale up the transform result to an NxN kernel (of course I'm not even sure if this procedure is the correct one).
Reply by ●March 24, 20072007-03-24
On Mar 24, 2:39 pm, "boiacan" <boia...@gmail.com> wrote:> Given a integer N, I need to generate a NxN kernel that approximates an > arbitrary frequency filter. So I can use the (small) kernel to filter the > image in spatial domain with convolution operations.The problem you're trying to solve is called "FIR filter design", as you're trying to find a finite convolution kernel (a finite impulse response, or FIR, filter) that best approximates an given frequency response. FIR filter design is covered in many textbooks on DSP, and many sites online, and there are several free software packages to help you. Google it (knowing the correct name will help)! (You're trying to solve the 2d version of the FIR problem, which is slightly more complicated than most of what you'll find online. However, there are many papers on multidimensional filter design which may help you. Alternatively, as a simple approximation you can simply apply 1d filters along each dimension, especially if the frequence response you're trying to apply is separable.)> I hope that this filter is correct. Despite this fact, my teacher suggest > me to take the inverse FFT of the filter to find out the kernel... but > how?Your teacher's suggestion is a reference to what is called the "window method" of FIR filter design. Look it up. (However, there may be other methods that produce better approximations, see e.g. http://gmeteor.sourceforge.net/ for references and code for one such method.) Regards, Steven G. Johnson