The flutter shutter camera simulator
fftw_routines.cpp
Go to the documentation of this file.
00001 /*fftw_routines.cpp*/
00002 /*
00003  * Copyright 2011, 2010 IPOL Image Processing On Line http://www.ipol.im/
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00024 using namespace std;
00025 
00026 #include <fftw3.h>
00027 
00032 
00045 void forward_fftw_simple(double* in,int width,int height,double* reOut,
00046                          double* imOut)
00047 {
00049     fftw_complex* spatial_repr;
00050     fftw_complex* frequency_repr;
00051     fftw_plan plan;
00052     spatial_repr= (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*width*height);
00053     frequency_repr= (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*width
00054                     *height);
00055 
00056 
00057     for (int i=0; i<width*height; i++)
00058     {
00059         spatial_repr[i][0] = in[i];
00060         spatial_repr[i][1] =  0.0f;
00061     }
00062 
00064     plan=fftw_plan_dft_2d(height, width, spatial_repr, frequency_repr,
00065                           FFTW_FORWARD, FFTW_ESTIMATE);
00066 
00068     fftw_execute(plan);
00069     for(int i=0; i<width*height; i++)
00070     {
00071         reOut[i]=frequency_repr[i][0];
00072         imOut[i]=frequency_repr[i][1];
00073     }
00074 
00075 
00076     fftw_destroy_plan(plan);
00077     fftw_free(spatial_repr);
00078     fftw_free(frequency_repr);
00079 
00080 }
00081 
00082 
00083 
00084 
00085 
00086 
00091 
00103 void backward_fftw_simple(double* reIn,
00104                           double* imIn,
00105                           double* out,
00106                           unsigned int width,
00107                           unsigned int height)
00108 {
00109 
00110     fftw_complex* spatial_repr;
00111     fftw_complex* frequency_repr;
00112 
00113     fftw_plan plan;
00114 
00115     spatial_repr=  (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*width*
00116                    height);
00117     frequency_repr=  (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*width*
00118                      height);
00119 
00120 
00121 
00122     for(unsigned i=0; i<width*height; i++)
00123     {
00124         frequency_repr[i][0]=reIn[i];
00125         frequency_repr[i][1]=imIn[i];
00126     }
00127 
00128     plan=fftw_plan_dft_2d(height, width, frequency_repr, spatial_repr,
00129                           FFTW_BACKWARD, FFTW_ESTIMATE);
00130 
00131     fftw_execute(plan);
00132 
00134     for (unsigned i=0; i<width*height; i++)
00135     {
00136         out[i]=spatial_repr[i][0]/(width*height);
00137     }
00138 
00139     fftw_destroy_plan(plan);
00140     fftw_free(spatial_repr);
00141     fftw_free(frequency_repr);
00142 }
00143 
00144 
00145 
00146 
00147 
00148 
00153 
00169 void fftw_multiplication(double* reTabImage,
00170                          double* imTabImage,
00171                          double* reTabFilter,
00172                          double* imTabFilter,
00173                          unsigned int width,
00174                          unsigned int height)
00175 {
00176 
00177     float a,b,c,d;
00178     unsigned int i;
00179 
00180     for (i=0; i< width * height; i++)
00181     {
00182         a = reTabImage[i];
00183         b = imTabImage[i];
00184         c = reTabFilter[i];
00185         d = imTabFilter[i];
00186 
00188         reTabImage[i] = a*c - b*d;
00189         imTabImage[i] = b*c + a*d;
00190 
00191 
00192     }
00193 
00194 }
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00206 
00221 void fftw_division(double* reTabImage,
00222                    double* imTabImage,
00223                    double* reTabFilter,
00224                    double* imTabFilter,
00225                    unsigned int width,
00226                    unsigned int height)
00227 {
00228 
00229     float a,b,c,d,temp;
00230     unsigned int i;
00231 
00232     for (i=0; i< width * height; i++)
00233     {
00234         a = reTabImage[i];
00235         b = imTabImage[i];
00236         c = reTabFilter[i];
00237         d = imTabFilter[i];
00238 
00240         temp=c*c+d*d;
00241         reTabImage[i] = (a*c+b*d)/temp;
00242         imTabImage[i] = (b*c-a*d)/temp;
00243 
00244     }
00245 
00246 }
00247 
00248 
 All Files Functions Variables Typedefs Defines