Go to the documentation of this file.00001 #ifndef mfpf_norm_vec_h_
00002 #define mfpf_norm_vec_h_
00003
00004
00005
00006
00007
00008 #include <vnl/vnl_vector.h>
00009 #include <vcl_algorithm.h>
00010
00011
00012 inline void mfpf_norm_vec(vnl_vector<double>& vec, double var_min=1.0E-6,
00013 double* pvar=0)
00014 {
00015 unsigned n=vec.size();
00016 double *v=vec.data_block();
00017 double sum=0.0,sum_sq=0.0;
00018 for (unsigned i=0;i<n;++i)
00019 {
00020 sum+=v[i]; sum_sq+=v[i]*v[i];
00021 }
00022 double mean = sum/n;
00023 double ss = vcl_max(var_min,sum_sq-n*mean*mean);
00024 double s = vcl_sqrt(ss);
00025
00026 for (unsigned i=0;i<n;++i) v[i]=(v[i]-mean)/s;
00027 if(pvar)
00028 *pvar=ss;
00029 }
00030
00031 #endif // mfpf_norm_vec_h_