00001 #ifndef _FFT_TOOLS_ 00002 #define _FFT_TOOLS_ 00003 00004 #include <fftw3.h> 00005 00006 #define cimg_display_type 1 00007 #define cimg_OS 1 00008 #include "CImg.h" 00009 00010 // ***************************************************************************** 00011 // 00012 // FFTtool class, created by Maria-Jose ESCOBAR (april 2007) 00013 // 00014 // This class was created in order to help the usage and implementation of 00015 // FFT transform and FFT filtering using the library fftw-3.1.2. 00016 // You just need to specify in your Makefile the location of the library's 00017 // header file (fftw3.h) and the library (libfftw3.a). The rest of the usage 00018 // is transparent for the user. 00019 // 00020 // See the description of each method to see how to use it. An example 00021 // of a filtering of two images can be found in testFFTtool.cpp file. 00022 // 00023 // Feel free to do any change in the current methods or add additional ones. 00024 // Of course, taking care of the correct functionallity of the class. 00025 // 00026 // ***************************************************************************** 00027 00028 using namespace cimg_library; 00029 00030 // ***************************************************************************** 00031 // Format used to deliver the FFT of images generated. This is a way to store 00032 // the complex image obtained when the FFT is calculated. 00033 // 00034 typedef struct cpxIm 00035 { 00036 CImg<double> real; 00037 CImg<double> imag; 00038 }COMPLEX_IMAG; 00039 00040 // ***************************************************************************** 00041 // Class definition: 00042 // 00043 class FFTtool 00044 { 00045 private: 00046 void transferInfoFromCImgToFFTW(CImg<double> cimgImag, fftw_complex *fftImag); 00047 void transferInfoFromFFTWToCImg(double *fftImag, CImg<double> &cimgImag); 00048 void transferInfoFromFFTWToComplex(fftw_complex *fftImag, COMPLEX_IMAG *cimgImag); 00049 void transferInfoFromComplexToFFTW(COMPLEX_IMAG *inCpx, fftw_complex *outfftw); 00050 00051 void createExtendedImage(CImg<double> &im, int xFinal, int yFinal); 00052 void loadSubUnit(CImg<double> &imag, CImg<double> sbImag, int x0, int y0); 00053 00054 public: 00055 FFTtool(); 00056 ~FFTtool(); 00057 00058 // ***************************************************************************** 00059 // Function: 00060 // void getFFTtransform(CImg<double> inImag, COMPLEX_IMAG *fftInImag); 00061 // 00062 // Description: 00063 // Calculates the FFT of an input image. 00064 // 00065 // Input Parameters: 00066 // inImag: input image to calculate FFT 00067 // 00068 // Return value: 00069 // A Complex image with the FFT of inImag 00070 // 00071 COMPLEX_IMAG getFFTtransform(CImg<double> inImag); 00072 00073 // ***************************************************************************** 00074 // Function: 00075 // void getFFTtransform(CImg<double> inImag, COMPLEX_IMAG *fftInImag, int desX, int desY); 00076 // 00077 // Description: 00078 // Calculates the FFT of an input image. If the input image is smaller than 00079 // the desired size, you can indicate the final size and an extended version of 00080 // the input image will be generated before calculate the FFT. The extended 00081 // version corresponds a bigger image with the input image in the center, the 00082 // rest of the image is filled with the mean value of inImag. 00083 // 00084 // Input Parameters: 00085 // inImag: input image to calculate FFT 00086 // desX: desired X size to extend the image size. 00087 // desY: desired Y size to extend the image size. 00088 // 00089 // Return value: 00090 // A Complex image with the FFT of inImag 00091 // 00092 COMPLEX_IMAG getFFTtransform(CImg<double> inImag, int desX, int desY); 00093 00094 // ***************************************************************************** 00095 // Function: 00096 // CImg<double> getFFTinverse(COMPLEX_IMAG fftImag); 00097 // 00098 // Description: 00099 // Calculates the FFT inverse of a complex image. 00100 // 00101 // Input Parameters: 00102 // fftImag: Complex image to calculate FFT inverse. 00103 // 00104 // Return value: 00105 // A CImg<double> image with the FFT inverse. 00106 // 00107 CImg<double> getFFTinverse(COMPLEX_IMAG fftImag); 00108 00109 // ***************************************************************************** 00110 // Function: 00111 // void multComplexImages(COMPLEX_IMAG imag1, COMPLEX_IMAG imag2, COMPLEX_IMAG *multResult); 00112 // 00113 // Description: 00114 // Multiplies two complex images pointwise. This is done to filter the frequency 00115 // contain of two images, normally the inputs are FFT transforms of images. 00116 // 00117 // Input Parameters: 00118 // imag1: Complex image to multiply. 00119 // imag2: Complex image to multiply. 00120 // 00121 // Return value: 00122 // A complex image with the result of the pointwise multiplication. 00123 // 00124 COMPLEX_IMAG multComplexImages(COMPLEX_IMAG imag1, COMPLEX_IMAG imag2); 00125 00126 // ***************************************************************************** 00127 // Function: 00128 // void quadrantShift(CImg<double> &img); 00129 // 00130 // Description: 00131 // If the input imag <img> is generated as the FFT inverse of the multiplication 00132 // of two FFT complex images, a shift in the quadrants of <img> is generated. 00133 // This function corrects the quadrant shifting and gives the correct arrange for <img>. 00134 // 00135 // Input Parameters: 00136 // img (by reference): Input CImg image with the quadrant shifting. 00137 // 00138 // Return value: 00139 // img: Input CImg image without the quadrant shifting. 00140 // 00141 void quadrantShift(CImg<double> &img); 00142 }; 00143 00144 00145 #endif // _FFT_TOOLS_ 00146 00147