The Flutter Shutter Code Optimizer
 All Files Functions Macros Pages
flutter_optimiser_gaussian.cpp
Go to the documentation of this file.
1 /*flutter_optmiser_gaussian.cpp*/
2 /*
3 * Copyright 2014 IPOL Image Processing On Line http://www.ipol.im/
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
28 #include <math.h>
33 #define eps 0.001//epsilon definition
34 
35 #ifndef ABS
36 
39 #define ABS(x) (((x) > 0) ? (x) : (-(x)))
40 #endif
41 
42 
43 #ifndef M_PI
44 
47 #define M_PI 3.14159265358979323846
48 #endif
49 
50 
51 
57 
75 void gaussian_optimiser(double* code,double sigma,int code_length,double deltat)
76 {
79 
80  double sum_code=0; // for the normalisation so that \int \alpha (t) dt=1.
81  // recall that \int \alpha(t)dt=\Deltat \sum \alpha_k.
82 
84  for ( int k=0; k<code_length; k++)
85  {
86 
88  double a=0;
89  double b=M_PI*(4*sigma)*deltat;
90  if (b>M_PI) b=M_PI;
91  // Recall that for the Gaussian model v_{max}=4sigma.
92  double h=(b-a)/2;
93  double s1=gaussian_integrand(sigma,deltat,a,k-round(code_length/2))+
94  gaussian_integrand(sigma,deltat,b,k-round(code_length/2));
95  double s2=0;
96  double s4=gaussian_integrand(sigma,deltat,a+h,
97  k-round(code_length/2));
98  double tn=h*(s1+4*s4)/3;
99  double ta=tn+2*eps*tn;
101  int zh=2;
102  int j;
103 
105  while (ABS(ta-tn)>eps*ABS(tn))
106  {
107  ta=tn;
108  zh=2*zh;
109  h=h/2;
110  s2=s2+s4;
111  s4=0;
112  j=1;
113  while (j<=zh)
114  {
115  s4=s4+gaussian_integrand(sigma,deltat,a+j*h,
116  k-round(code_length/2+.5));
117  j=j+2;
118  }
119  tn = h*(s1+2*s2+4*s4)/3;
120  }//End of the loop, integral evaluated
121 
122  code[k]=(double)tn; //storing the code.
123  sum_code=sum_code+code[k];
124  }
125 
126  for ( int k=0; k<code_length; k++)
127  code[k]=code[k]/(deltat*sum_code);
128 
129 }
130 
131 
132 
133 
139 
156 double gaussian_integrand(double sigma,double deltat,
157  double xi, int k)
158 {
159 
160  if (xi!=0)
161  {
162  return( pow(xi/(2*sin(xi/2)),0.5)*
163  //This is \frac 1 {\sqrt \sinc (\frac \xi {2\pi})}
164  pow(gaussian_w(sigma,xi/deltat),0.25)*cos(k*xi));
165  }
166  else
167  {
168  return ( pow(gaussian_w(sigma,0),0.25));
169  }
170 
171 
172 }
173 
174 
175 
176 
177 
178 
179 
180 
186 
198 double gaussian_w(double sigma, double xi)
199 {
200  double velocity_max=4*sigma;
201  if (ABS(xi)>velocity_max*M_PI) return(0);
202  // to speed up some, as if ABS(xi)>velocity_max*M_PI*deltat by construction
203  //the integrand is zero.
204  double a=sigma/1000;//Avoids singularity, OK since the
205  //function is in L^1 see alsopage 7 and Algorithm 1 step 3.
206  double b=velocity_max;
207  double h=(b-a)/2;
208  double s1=gaussian_w_integrand(a,sigma,xi)+
209  gaussian_w_integrand(b,sigma,xi);
210  double s2=0;
211  double s4=gaussian_w_integrand(a+h,sigma,xi);
212  double tn=h*(s1+4*s4)/3;
213  double ta=tn+2*eps*tn;
215  int zh=2;
216  int j;
217 
218  while (ABS(ta-tn)>eps*ABS(tn))
219  {
220  ta=tn;
221  zh=2*zh;
222  h=h/2;
223  s2=s2+s4;
224  s4=0;
225  j=1;
226  while (j<=zh)
227  {
228  s4=s4+gaussian_w_integrand(a+j*h,sigma,xi);
229  j=j+2;
230  }
231  tn = h*(s1+2*s2+4*s4)/3;
232  }
233  return(tn);
234 
235 }
236 
237 
238 
239 
245 
258 double gaussian_w_integrand(double velocity, double sigma,
259  double xi)
260 {
261  if (ABS(xi)<ABS(M_PI*velocity))
264  {
265  return(exp(-velocity*velocity/(2*sigma*sigma))/ABS(velocity));
266  }
267  else
268  {
269  return(0);
270  }
271 }
double gaussian_integrand(double sigma, double deltat, double xi, int k)
Function to integrate in order to compute the a_k coefficient of the code; gaussian motion model...
void gaussian_optimiser(double *code, double sigma, int code_length, double deltat)
Computes the a_k coefficients of the code; gaussian motion model.
double gaussian_w(double sigma, double xi)
Computes the W() function; gaussian motion model. This is equation (15): W():={}^{4{ N}} ({{-v^2}{2{ ...
#define ABS(x)
double gaussian_w_integrand(double velocity, double sigma, double xi)
Function to integrate in velocity to get the W function; gaussian motion model. This is the integrand...