5
$\begingroup$

Note: This is a followup question of

  1. How can I create a custom band-pass filter?.
  2. Can you explain the following python source code?.
  3. Bandpass filter bank.

Suppose, I have an equation of a filter as follows,

$$ h(x, y) = \frac{1}{1 + 0.414 (x + y)^{2n}} $$

I know that this is an equation in the spatial domain.

So, this is how I obtain a filtered image:

  1. I create a, say, $3\times 3$ kernel using that equation where ($x$: from $0$ to $2$) and ($y$: from $0$ to $2$).

  2. I pad the kernel and the image to the same size.

  3. I apply FFT to kernel and the image.

  4. Multiply them element by element and apply I-FFT to the result.

  5. Convert the result to an image format like Bmp and so on.

.

Now, suppose, I have the following equation,

$$H(u, v) = \frac{1}{1 + 0.414(u + v)^{2n}}$$

I know that this is an equation in the frequency domain.

  • So, how am I going to create the kernel?

In the previous case, ($x$: $0$ to $2$) and ($y$: $0$ to $2$).

  • What would be the starting and ending values of $u$ and $v$ in the loop?
  • What would be the procedure to apply the kernel to an image?
  • How should I multiply the kernel and the image?
$\endgroup$
3
  • $\begingroup$ re: 2. step. You pad them to the same size, right? $\endgroup$ Sep 3, 2016 at 10:31
  • $\begingroup$ @MarcusMüller, Yes. $\endgroup$
    – user18425
    Sep 3, 2016 at 10:31
  • $\begingroup$ @MarcusMüller, No answer !? $\endgroup$
    – user18425
    Sep 3, 2016 at 14:51

1 Answer 1

5
$\begingroup$

It appears you need to study a bit on convolutional filtering of images, specifically on overlap add/ overlap save methods.

From the links I can see your objective is to apply the filter defined in the second equation i.e, the frequency domain one. The first link's accepted answer seems to be wrong (i didn't go through the code, clearly since the images shown by the paper and answer do not match).

Now the method you are using to apply the filter in the spatial domain is wrong. I'm assuming by padding you mean zero padding. The objective of zero padding before applying fft is to increase the resolution in the frequency domain. So imagine I have a 1D sine wave of 50 Hz. Taking fft of this signal would give a peak at the 50 Hz point with some additional values at different frequencies. This is because the sine is not pure sine since the signal is limited in time. If you had an infinitely long signal you would get a single value at 50 Hz. Padding the signal and then taking fft would still give the similar result but with more resolution on what additional frequencies exists.

In contrast convolution filter is essentially convolving 2 signals. $$ y(t) = \int_{\tau = 0}^{\inf} h(\tau)x(t-\tau)d\tau $$ In 2D, if we have a 3x3 filter kernel, we first multiply the first 3x3 block of the input with the kernel and then shift the kernel by one column. Then we multiply the next 3x3 with kernel and add the overlapping pixel values.

for small kernel sizes (say 3x3 or 5x5) this approach maybe faster. Using fft is alluring when working with large kernel sizes. The approach is go block by block and use the overlap save/add method (you can find a lot of info on this just google it for 2D). The reason we need to use overlap method is because fft facilitates circular convolution and not linear convolution (but circular convolution can be made to behave like linear convolution by adjusting the input and kernel sizes).

Once you understand the method then it is just deciding on the kernel size and using the equation for those u,v values. Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.