CImg output i am getting
Desired FFT ouptut.Checked using ImageJ
#include "CImg.h"
using namespace cimg_library;
int main(int argc, char * argv[]) {
const char * input_file = "Lenna.png";
CImg<unsigned char> * input = new CImg<unsigned char>(input_file);
//resize_fft(*input); //Resize the image for the FFT
//CImg<unsigned char> gray = any2gray(*input); //to single-channel grayscale image
//free(input);
CImgList<unsigned char> fft = input->get_FFT();
CImg<unsigned char>::FFT(fft[0], fft[1], false);
fft[0].save("fft.jpg");
return 1;
}
I tried this code . But i am getting noise image.Anybody could help me to get the desired fft image? i am running on Linux. i have posted the images above.
Several things wrong here in your code:
By (mathematical) definition, result of a FFT is a float-valued image. There is no way you can accurately store a FFT image into a
CImgList<unsigned char>
. Use aCImgList<float>
orCImgList<double>
instead when defining yourfft
variable. Your currentfft
is defined as aCImgList<unsigned char>
, there is no way CImg can store float-values inside.CImg<T>::get_FFT()
always returns aCImgList<float>
or aCImgList<double>
, depending on the original typeT
(ifT
isunsigned char
, result will be aCImgList<float>
probably). But if you writethen, of course the result of
get_FFT()
is rounded back tounsigned char
, which is not what you want.So, the correct code would be :
At this point,
fft[0]
is the real part of the FFT, andfft[1]
the imaginary part of the FFT. Note that it does not correspond to the classical Fourier visualization of images you'll find on the web, which are actually displayed as the centered module of the FFT (less often with the phase), e.g.https://cs.appstate.edu/ret/imageJ/PClabs/imlab/FFT/gif/imj-fft1.gif
Getting this requires additional steps to transform the complex-valued FFT you get as this scalar image representation (which is actually good only for visualization, not for actual computations in the Fourier space, as you lose half of the data of the FFT).
Oh, and before saying any library you use has a lack of design, ask yourself if there is something that maybe you have not understood. Looking at your code makes me think that you still have a lot to learn before having a relevant opinion on how to design a programming library.