45 #define ABS(x) (((x) > 0) ? (x) : (-(x)))
53 #define M_PI 3.14159265358979323846
79 int main(
int argc,
char **argv)
84 std::cerr <<
" ***************************************** " << std::endl
85 <<
" ********** Flutter shutter code calculator ****** " << std::endl
86 <<
" EXAMPLE: ./flutter_optimizer 0 0.25 52 5 code.txt " << std::endl
87 <<
" TF_code.txt rendement.txt mean_sdt.txt " << std::endl
88 <<
" Usage: input : motion _model and parameter******** " << std::endl
89 <<
" Code_length, Exposure time factor multiplication*** " << std::endl
90 <<
" code_length exposure_time_factor code_file_name**** " << std::endl
91 <<
"Fourier_transform_file_name efficency_file_name***** " << std::endl
92 <<
" efficency_rist_file_name*************************** " << std::endl
93 <<
" *************************************************** " << std::endl
94 <<
" ************* Yohann Tendero, 2014 ************** " << std::endl
95 <<
" *************************************************** " << std::endl;
120 int flag_motion_model=atoi(argv[1]);
122 double motion_model_parameter=
ABS(atof(argv[2]));
126 int code_length=atoi(argv[3]);
127 double exposure_factor=atof(argv[4]);
130 double* code =
new double[code_length];
131 const int num_plot_points=300;
133 double velocity_max=motion_model_parameter;
134 if (flag_motion_model==0) velocity_max=4*motion_model_parameter;
137 char* code_file_name=argv[5];
138 char* TF_code_file_name=argv[6];
139 char* SNR_comparison_file_name=argv[7];
140 char* mean_sdt_file_name=argv[8];
149 motion_model_parameter);
150 double deltat=exposure_factor*T_star/code_length;
153 if (deltat*velocity_max>1)
155 std::cerr <<
" Deltat too big! convergence not guaranteed"
157 std::cerr <<
" Increase the code length L." << std::endl;
166 if (flag_motion_model==0)
170 if (flag_motion_model==1)
188 ofstream file_code(code_file_name, ios::out | ios::trunc);
192 for (
int k=0; k<code_length; k++)
194 file_code << code[k] <<
";" << endl;
200 cerr <<
"Unable to open file !" << endl;
214 if (flag_motion_model==0) w_0=
gaussian_w(motion_model_parameter,0);
215 if (flag_motion_model==1) w_0=
uniform_w(motion_model_parameter,0);
219 ofstream file_TFcode(TF_code_file_name, ios::out | ios::trunc);
222 if (flag_motion_model==0)
223 for (
double xi=-2*velocity_max*
M_PI; xi<=2*velocity_max*
M_PI;
224 xi=xi+4*velocity_max*M_PI/num_plot_points)
228 << pow(
gaussian_w(motion_model_parameter, xi)/w_0,0.25)
232 if (flag_motion_model==1)
233 for (
double xi=-2*velocity_max*M_PI; xi<=2*velocity_max*
M_PI;
234 xi=xi+4*velocity_max*M_PI/num_plot_points)
238 << pow(
uniform_w(motion_model_parameter, xi)/w_0,0.25)
247 cerr <<
"Unable to open file !" << endl;
257 double* average_gain_RMSE =
new double[num_plot_points];
258 double* average_gain_mu =
new double[1];
259 double* std_dev_gain_sigma =
new double[1];
260 if (flag_motion_model==0) velocity_max=4*motion_model_parameter;
263 flag_motion_model, motion_model_parameter,
264 deltat,num_plot_points,
269 motion_model_parameter,
275 ofstream file_comparison_file_name(SNR_comparison_file_name,
276 ios::out | ios::trunc);
278 if (file_comparison_file_name)
280 double velocity=-velocity_max;
281 for (i=0; i<num_plot_points; i++)
283 file_comparison_file_name << velocity
285 << average_gain_RMSE[i]
287 << average_gain_mu[0]
290 motion_model_parameter)
294 velocity=velocity+2*velocity_max/num_plot_points;
298 file_comparison_file_name.close();
301 cerr <<
"Unable to open file !" << endl;
303 printf(
"Maximum blur support for optimal snapshot \
304 (\\Delta t^* |velocity_{max}|) in pixel(s): %f\n",
305 T_star*velocity_max);
310 ofstream file_mean_sdt_file_name(mean_sdt_file_name, ios::out | ios::trunc);
312 if (file_mean_sdt_file_name)
315 file_mean_sdt_file_name
316 <<
"Gain with respect to the optimal snapshot \
317 in terms of RMSE, summary" << std::endl
318 <<
"*average gain: " <<
319 average_gain_mu[0] << std::endl
320 <<
"*Standard deviation: " << std_dev_gain_sigma[0] << endl;
321 file_mean_sdt_file_name.close();
324 cerr <<
"Unable to open file !" << endl;
327 delete [] average_gain_RMSE;
328 delete [] average_gain_mu;
329 delete [] std_dev_gain_sigma;
void average_gain_in_terms_of_RMSE(double *code, int code_length, double tilde_deltat_star, int flag_motion_model, double motion_model_parameter, double deltat, int num_plot_points, double *G_of_v, double *average_gain_mu)
This function implements equation (24): := G(v) (v) dv.
double optimal_snapshot(int flag_motion_model, double motion_model_parameter)
Given a motion model compute the optimal exposure time for a snaphot. The minimization is done by sca...
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{ ...
double probability_density(double velocity, int flag_motion_model, double motion_model_parameter)
Given a velocity velocity, the motion model and its parameters the function computes the probability...
double abs_hat_alpha(double *code, int code_length, double xi, double deltat)
Given a code compute the modulus of the Fourier transform of the Flutter-Shutter function, see equation (2): ()= t {sinc}({ t}{2}) e^{-{i t}{2}} {k=0}^{L-1} e^{-ik t}.
void std_dev_gain_in_terms_of_RMSE(int flag_motion_model, double motion_model_parameter, int num_plot_points, double *G_of_v, double *average_gain_mu, double *std_dev_gain_sigma)
This function implements equation (25): :={ |G(v)- G(u) (u) du|^2 (v) dv}.
int main(int argc, char **argv)
main function call