2

I am using opencv to compute a butterworth filter of an image. The image in questions is a physical parameter, i.e. the pressure, in some units, at every nodal point. It is not just gray scale or color values.

I have followed the examples here: http://docs.opencv.org/2.4/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.html http://breckon.eu/toby/teaching/dip/opencv/lecture_demos/c++/butterworth_lowpass.cpp

I have successfully implemented this filter. I.E. I can DFT, create the filter kernel, apply it, and inverse Fourier transform back.

However, the magnitude of the values after the idft are completely off.

In particular, I replicate lines of code that can be found in both the above links:

    // Perform Inverse Fourier Transform
    idft(complexImg, complexImg);
    split(complexImg, planes);
    imgOutput = planes[0].clone();

In the above code segment, 1.) I compute the idft of complexImg and save it to complexImg. 2.) I split complexImg into real and imaginary parts (which is saved in planes[0] and planes[1], respectively) 3.) I save the save the real part to imgOutput as my original image was real.

However, if the original image, i.e. imgInput had a mean value of the order of O(10^-1), imgOutput has a mean value of the order of O(10^4 to 10^5). It seems some type of normalization is needed? In the above example links, the values are normalized between 0 and 1 for viewing purposes, but that is not what I need.

Any help will be appreciated.

Thank you.

gsandhu
  • 489
  • 5
  • 13

2 Answers2

1

The problem was solved by normalizing by 2*N, where N is the number of pixels in the image.

i.e.

   imgOutput = imgOutput/imgOutput.cols/imgOutput.rows/2;
gsandhu
  • 489
  • 5
  • 13
0

According to the documentation: https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#idft

Note

None of dft and idft scales the result by default. So, you should pass DFT_SCALE to one of dft or idft explicitly to make these transforms mutually inverse.

Therefore something liek this would fix it: icvdft=cv.idft(dft_array,flags=cv.DFT_SCALE)

icypy
  • 3,062
  • 5
  • 25
  • 27