The Flutter Shutter Code Optimizer
 All Files Functions Macros Pages
flutter_optimiser_uniform.cpp
Go to the documentation of this file.
1 /*flutter_optimiser_uniform.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 */
27 #include <math.h>
32 #define eps 0.001//epsilon definition
33 
34 #ifndef ABS
35 
38 #define ABS(x) (((x) > 0) ? (x) : (-(x)))
39 #endif
40 #ifndef M_PI
41 
44 #define M_PI 3.14159265358979323846
45 #endif
46 
47 
53 
70 void uniform_optimiser(double* code, double velocity_max,
71  int code_length, double deltat)
72 {
75 
76  double sum_code=0; // for the normalisation so that \int \alpha (t) dt=1.
77  // recall that \int \alpha(t)dt=\Deltat \sum \alpha_k
78 
80  for ( int k=0; k<code_length; k++)
81  {
83  double a=0;
84  double b=M_PI*velocity_max*deltat; // \pi v_{max} \Deltat
85  if (b>M_PI) b=M_PI;
86  double h=(b-a)/2;
87  double s1=uniform_integrand(velocity_max,deltat,a,
88  k-round(code_length/2))+
89  uniform_integrand(velocity_max,deltat,b,
90  k-round(code_length/2));
91  double s2=0;
92  double s4=uniform_integrand(velocity_max,deltat,a+h,
93  k-round(code_length/2));
94  double tn=h*(s1+4*s4)/3;
95  double ta=tn+2*eps*tn;
96  int zh=2;
98  int j;
99 
101  while (ABS(ta-tn)>eps*ABS(tn))
102  {
103  ta=tn;
104  zh=2*zh;
105  h=h/2;
106  s2=s2+s4;
107  s4=0;
108  j=1;
109  while (j<=zh)
110  {
111  s4=s4+uniform_integrand(velocity_max,deltat,a+j*h,
112  k-round(code_length/2+.5));
113  j=j+2;
114  }
115  tn = h*(s1+2*s2+4*s4)/3;
116  }//End of the loop, integral evaluated
117 
118  code[k]=(double)tn; //storing the code.
119  sum_code=sum_code+code[k];
120  }
121  // loop for code normalization.
122  for ( int k=0; k<code_length; k++)
123  code[k]=code[k]/(deltat*sum_code);
124 }
125 
126 
132 
151 double uniform_integrand(double velocity_max,double deltat, double xi,
152  int k)
153 {
155 
156 
157  if (xi!=0)
158  {
159  return( pow((xi/2)/(sin(xi/2)),0.5)*//
160  //This is \frac 1 {\sqrt \sinc (\frac \xi {2\pi})}
161  pow(uniform_w(velocity_max,xi/deltat),0.25)*
162  cos(k*xi));
163  }
164  else
165  {
166 
167  return ( pow(uniform_w(velocity_max,0),0.25)) ;
168  }
169 
170 }
171 
172 
178 
189 double uniform_w(double velocity_max, double xi)
191 {
193 
195  if (ABS(xi)>velocity_max*M_PI) return(0);
196  // to speed up some: indeed, the function w defined in equation (16)
197  // is supported on $[-\pi |v_{max}, \pi |v_{max}|]$.
198 
199  //(ELSE) in the support of $\rho$
200 
205 
206  double a=velocity_max/1000;//Avoids singularity, OK since
207  //the function is in L^1 see also remark 1 page 8 and Algorithm 1 step 3.
208  double b=velocity_max;
209 
210  double h=(b-a)/2;
211  double s1=uniform_w_integrand(a,xi)+
212  uniform_w_integrand(b,xi);
213  double s2=0;
214  double s4=uniform_w_integrand(a+h,xi);
215  double tn=h*(s1+4*s4)/3;
216  double ta=tn+2*eps*tn;
217  int zh=2;
218  int j;
219 
221  while (ABS(ta-tn)>eps*ABS(tn))
222  {
223  ta=tn;
224  zh=2*zh;
225  h=h/2;
226  s2=s2+s4;
227  s4=0;
228  j=1;
229  while (j<=zh)
230  {
231  s4=s4+uniform_w_integrand(a+j*h,xi);
232  j=j+2;
233  }
234  tn = h*(s1+2*s2+4*s4)/3;
235  }
236  return(tn);
237 
238 }
239 
240 
246 
255 double uniform_w_integrand(double velocity, double xi)
260 {
261 
262  if (ABS(xi)<ABS(M_PI*velocity))
263  {
264  return(1/(ABS(velocity)));
265  }
266  else return(0);
267 }
double uniform_integrand(double velocity_max, double deltat, double xi, int k)
Function to integrate (in ) in order to compute the a_k coefficient of the code; uniform motion model...
void uniform_optimiser(double *code, double velocity_max, int code_length, double deltat)
Functions for the uniform motion model:
double uniform_w_integrand(double velocity, double xi)
Function to integrate in velocity to get the w function; uniform motion model. This is the integrand ...
#define ABS(x)
double uniform_w(double velocity_max, double xi)
Compute the weight function () for a uniform velocity.
#define M_PI