The Flutter Shutter Code Optimizer
flutter_optimizer_uniform.cpp
Go to the documentation of this file.
00001 /*flutter_optimizer_uniform.cpp*/
00002 /*
00003 * Copyright 2014 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 */
00027 #include <math.h>
00028 #include "flutter_optimizer_uniform.h"
00032 #define eps   0.001//epsilon definition
00033 
00034 #ifndef ABS
00035 
00038 #define ABS(x)    (((x) > 0) ? (x) : (-(x)))
00039 #endif
00040 #ifndef M_PI
00041 
00044 #define M_PI 3.14159265358979323846
00045 #endif
00046 
00047 
00053 
00065 void uniform_optimisator(double* code, double motion_model_parameter,
00066                          int code_length, double deltat)
00067 {
00070 
00071    double sum_code=0; // for the normalisation so that \int  \alpha (t) dt=1.
00072    // recall that \int \alpha(t)dt=\Deltat \sum \alpha_k
00073 
00075     for ( int k=0; k<code_length; k++)
00076     {
00082         double a=0;
00083         double b=M_PI*motion_model_parameter*deltat; // \pi v_{max} \Deltat
00084         if (b>M_PI) b=M_PI; 
00085         // Recall that for the Uniform model v_{max}=motion_model_parameter.
00086         double h=(b-a)/2;
00087         double s1=uniform_integrand(motion_model_parameter,deltat,a,
00088                                     k-round(code_length/2+.5))+
00089                   uniform_integrand(motion_model_parameter,deltat,b,
00090                                     k-round(code_length/2+.5));
00091         double s2=0;
00092         double s4=uniform_integrand(motion_model_parameter,deltat,a+h,
00093                                     k-round(code_length/2+.5));
00094         double tn=h*(s1+4*s4)/3;
00095         double ta=tn+2*eps*tn; 
00096 
00097         int zh=2;
00098         int j;
00099 
00101         while (ABS(ta-tn)>eps*ABS(tn))
00102         {
00103             ta=tn;
00104             zh=2*zh;
00105             h=h/2;
00106             s2=s2+s4;
00107             s4=0;
00108             j=1;
00109             while (j<=zh)
00110             {
00111                 s4=s4+uniform_integrand(motion_model_parameter,deltat,a+j*h,
00112                                         k-round(code_length/2+.5));
00113                 j=j+2;
00114             }
00115             tn = h*(s1+2*s2+4*s4)/3;
00116         }//End of the loop, integral evelocityaluated
00117 
00118         code[k]=(double)tn; //storing the code.
00119         sum_code=sum_code+code[k];
00120     }
00121     // loop for code normalization.
00122     for ( int k=0; k<code_length; k++)
00123      code[k]=code[k]/(deltat*sum_code);
00124 }
00125 
00126 
00132 
00145 double uniform_integrand(double motion_model_parameter,double deltat, double xi,
00146                          int k)
00147 {
00149 
00150 
00151     if (xi!=0)
00152     {
00153         return( ((xi/2)/(sin(xi/2)))*
00154                 pow(uniform_w(motion_model_parameter,xi/deltat),0.25)*
00155                 cos((k+.5)*xi));
00156     }
00157     else
00158     {
00160         return ( pow(uniform_w(motion_model_parameter,0),0.25)) ;
00161     }
00162 
00163 }
00164 
00165 
00171 
00180 double uniform_w(double motion_model_parameter, double xi)
00182 {
00184 
00186     if (ABS(xi)>motion_model_parameter*M_PI) return(0);
00187     // to speed up some: indeed, the function w defined in equation (10)
00188     // is supported on $[-\pi |v_{max}, \pi |v_{max}|]$. Note that
00189     // for the unform motion model motion_model_parameter corresponds
00190     // to v_{max}.
00191 
00192     //(ELSE) in the support of $\rho$
00193 
00198 
00199     double a=motion_model_parameter/1000;//Avoids singularity, OK since
00200     //the function is in L^1 see also remark 1 page 8 and Algorithm 1 step 3.
00201     double b=motion_model_parameter; // Recall that motion_model_parameter
00202     // is equal to |v_{max}| for the uniform motion model, see (15).
00203     double h=(b-a)/2;
00204     double s1=uniform_w_integrand(a,xi)+
00205               uniform_w_integrand(b,xi);
00206     double s2=0;
00207     double s4=uniform_w_integrand(a+h,xi);
00208     double tn=h*(s1+4*s4)/3;
00209     double ta=tn+2*eps*tn;
00210     int zh=2;
00211     int j;
00212 
00214     while (ABS(ta-tn)>eps*ABS(tn))
00215     {
00216         ta=tn;
00217         zh=2*zh;
00218         h=h/2;
00219         s2=s2+s4;
00220         s4=0;
00221         j=1;
00222         while (j<=zh)
00223         {
00224             s4=s4+uniform_w_integrand(a+j*h,xi);
00225             j=j+2;
00226         }
00227         tn = h*(s1+2*s2+4*s4)/3;
00228     }
00229     return(tn);
00230 
00231 }
00232 
00233 
00239 
00247 double uniform_w_integrand(double velocity, double xi)
00252 {
00253 
00254     if (ABS(xi)<ABS(M_PI*velocity))
00255     {
00256         return(1/(ABS(velocity)));
00257     }
00258     else return(0);
00259 }
 All Files Functions Defines