Go to the documentation of this file.00001 #include <cstring>
00002 #include <cmath>
00003 #include <cstdlib>
00004
00005 #include <iostream>
00006 using namespace std;
00007
00008
00009
00010
00011 class EHBSW
00012 {
00013 protected:
00014 const int* I_pu;
00015 float *Iout_pf;
00016 int* wavefront1_pu;
00017 int* wavefront2_pu;
00018 float* thehist_pu;
00019 int w_u;
00020 int h_u;
00021 int hs_u;
00022 int vs_u;
00023
00024
00025 int x_u;
00026 int y_u;
00027
00028 void initline(int y_line)
00029 {
00030 memset(wavefront1_pu,0,vs_u*sizeof(int));
00031 memset(wavefront2_pu,0,vs_u*sizeof(int));
00032
00033 x_u=hs_u;
00034 for(int j=y_line-hs_u; j<=y_line+hs_u; j++)
00035 {
00036 for(int i=0; i<2*hs_u+1; i++)
00037 {
00038 ++(wavefront1_pu[I_pu[i+w_u*j]]);
00039 }
00040 }
00041 for(int k=0; k<vs_u; k++)
00042 {
00043 thehist_pu[k]=wavefront1_pu[k];
00044 }
00045 this->process_hist();
00046 }
00047
00048
00049 void advance_one()
00050 {
00051 x_u++;
00052 int i1=x_u + hs_u;
00053 int i2=x_u - hs_u - 1;
00054 for(int j=y_u-hs_u; j<=y_u+hs_u; j++)
00055 {
00056 wavefront1_pu[I_pu[i1+w_u*j]]++;
00057 wavefront2_pu[I_pu[i2+w_u*j]]++;
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 for(int k=0; k<vs_u; k++)
00070 {
00071 thehist_pu[k]=wavefront1_pu[k]-wavefront2_pu[k];
00072
00073 }
00074
00075 this->process_hist();
00076 }
00077
00078 virtual void process_hist() = 0;
00079
00080 public:
00084 EHBSW(float* Ioutin, int* Iin, int win, int hin, int hsin, int vsin):w_u(win),h_u(hin),hs_u(hsin)
00085 {
00086 vs_u=vsin+1;
00087 Iout_pf=Ioutin;
00088 memset(Iout_pf,0,win*hin*sizeof(float));
00089
00090
00091 I_pu=Iin;
00092 wavefront1_pu=new int[vs_u];
00093 wavefront2_pu=new int[vs_u];
00094 thehist_pu=new float[vs_u+1];
00095 thehist_pu[vs_u] = 1.0;
00096
00097
00098
00099
00100
00101 }
00102
00103 EHBSW(const EHBSW& a);
00104
00105 ~EHBSW()
00106 {
00107 delete [] wavefront1_pu;
00108 delete [] wavefront2_pu;
00109 delete [] thehist_pu;
00110
00111 }
00112
00113 void run_image()
00114 {
00115
00116 for(y_u=hs_u; y_u<h_u-hs_u; y_u++)
00117 {
00118 this->initline(y_u);
00119 for(int i=hs_u+1; i<w_u-hs_u; i++)
00120 {
00121 this->advance_one();
00122 }
00123 }
00124 }
00125
00126 };
00127
00128
00129 class EHBSW_PowNorm : public EHBSW
00130 {
00131 private:
00132 const float* classifier_pf;
00133
00134 void process_hist()
00135 {
00136
00137
00138 float N=0;
00139
00140
00141
00142 float score=0;
00143 for (int v=0; v<vs_u; v++)
00144 {
00145
00146 score += sqrt(thehist_pu[v+1])*classifier_pf[v];
00147 N += thehist_pu[v+1];
00148 }
00149
00150
00151 N=sqrt(N);
00152 if (x_u<hs_u || x_u>w_u-hs_u)
00153 cout<<"alarm! "<<x_u<<endl;
00154 Iout_pf[x_u+y_u*w_u]=1.0/(1.0+exp(-score/N));
00155 }
00156 public:
00157
00158 EHBSW_PowNorm(float* Ioutin, int* Iin, int win, int hin, int hsin, int vsin, float* c): EHBSW(Ioutin, Iin, win, hin, hsin, vsin)
00159 {
00160
00161
00162 classifier_pf=c;
00163 }
00164
00165 ~EHBSW_PowNorm()
00166 {
00167
00168 }
00169 };
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 class EHBSW_LinHist_L1 : public EHBSW
00184 {
00185 private:
00186 const float* classifier_pf;
00187
00188
00189 void process_hist()
00190 {
00191
00192 float N=0;
00193
00194
00195
00196 float score=0;
00197 for (int v=0; v<vs_u; v++)
00198 {
00199
00200 score += thehist_pu[v]*classifier_pf[v];
00201 N += thehist_pu[v];
00202 }
00203
00204
00205 Iout_pf[x_u+y_u*w_u]=score/N;
00206 }
00207 public:
00208
00209 EHBSW_LinHist_L1(float* Ioutin, int* Iin, int win, int hin, int hsin, int vsin, float* c): EHBSW(Ioutin, Iin, win, hin, hsin, vsin)
00210 {
00211
00212
00213 classifier_pf=c;
00214 }
00215
00216 ~EHBSW_LinHist_L1()
00217 {
00218
00219 }
00220 };