2

I need to implement a very simple filter that suppresses a range of frequencies. Then I need to compute the inverse Fourier transform and save the new image.

I am using the CImg library ( C++ ). So far I have done:

const CImg<unsigned char> img(source_img);
CImgList<> F = img.get_FFT();

and I am stuck here. F is a a list of two CImg objects the real and Imaginary part , correct?

Having this F how I suppress frequencies and reconstruct the new Image?

P.S. This is a homework, so I don't want a solution but an explanation of what to do, how to do it and why.

mtrw
  • 34,200
  • 7
  • 63
  • 71
gosom
  • 1,299
  • 3
  • 16
  • 35
  • 1
    It depends on the filter, and on whether the CImg implementation does the fftshift or not. In any case, one type of simple filtering would be to set some of the pixels on the transformed image to 0 (e.g. based on distance from the point/frequency you need) and then transform the image back with inverse fft. – Photon Nov 10 '14 at 11:09
  • CImg does not implement fftshift. Could you describe me the steps needed (assuming fftshift is available?) – gosom Nov 10 '14 at 11:15
  • 1
    fftshift simply moves the DC (low frequencies) location to the center of the image, instead of the corners. If you want a low pass filter, you need to zero the locations with high frequencies (far from DC), and if you want high pass, just zero the area around the DC. – Photon Nov 10 '14 at 11:19
  • "Setting some pixels to zero" is equivalent to multiplying with a black&white filter in the FFT domain. In turn, that's equivalent to a convolution in the spatial domain. And your black&white filter has horrible ringing. It will look like an overcompressed JPG. – MSalters Nov 10 '14 at 14:23

1 Answers1

3

Since it's homework, do feel free to experiment.

The first step you need to get working is to directly transform the image back, and get the original input. If this doesn't work, you'd be quite happy to catch it early.

The second step is to just zero some part of the FFT, transform the result back, and see how it differs. Each pixel in the FFT represents a frequency in the input, so experiment to find the relation. Then explain that relation to yourself.

Finally, once you have figured out which are of pixels you want to zero and which ones to keep, create a black& white mask, turn that into a greyscale image, and then blur it. A sharp edge in the FFT domain has an infinite support in the image domain - in practice, that causes additional fake edges. It's better to have a single blurred edge.

MSalters
  • 173,980
  • 10
  • 155
  • 350