00001 #ifndef Impala_Core_Trec_TrecFeature_h
00002 #define Impala_Core_Trec_TrecFeature_h
00003
00004 #include <vector>
00005 #include "Core/Array/Element/E1Sqrt.h"
00006 #include "Core/Array/Pattern/PatM9N4PixOp.h"
00007 #include "Core/Array/ColorSpace.h"
00008 #include "Core/Array/Scale.h"
00009 #include "Core/Array/ProjectRange.h"
00010 #include "Core/Array/RecGauss.h"
00011 #include "Core/Array/GaussDerivative.h"
00012
00013 namespace Impala
00014 {
00015 namespace Core
00016 {
00017 namespace Trec
00018 {
00019
00020
00021 using namespace Impala::Core::Array;
00022
00023 bool
00024 IsWfeat(int f)
00025 {
00026 int i = f % 4;
00027 return i >= 2;
00028 }
00029
00030 template<class DstArrayT, class SrcArrayT>
00031 class M9N4poConFeat
00032 {
00033 public:
00035 typedef Pattern::TagTransInVar TransVarianceCategory;
00036
00038 typedef Pattern::TagCallValue CallCategory;
00039
00040 typedef typename DstArrayT::StorType DstStorT;
00041 typedef typename DstArrayT::ArithType DstArithT;
00042 typedef typename SrcArrayT::ArithType SrcArithT;
00043
00045 M9N4poConFeat(SrcArithT scale)
00046 {
00047 _scale = scale;
00048 }
00049
00051 void
00052 DoIt(DstStorT* Cl, DstStorT* Cll, DstStorT* Clw, DstStorT* Cllw,
00053 const SrcArithT& E, const SrcArithT& Ex, const SrcArithT& Ey,
00054 const SrcArithT& El, const SrcArithT& Elx, const SrcArithT& Ely,
00055 const SrcArithT& Ell, const SrcArithT& Ellx, const SrcArithT& Elly)
00056 {
00057 *Cl = El / E;
00058 *Cll = Ell / E;
00059 SrcArithT tmpx = Elx*E - El*Ex;
00060 SrcArithT tmpy = Ely*E - El*Ey;
00061 *Clw = ( Element::E1Sqrt(tmpx*tmpx + tmpy*tmpy) / (E*E) ) * _scale;
00062 tmpx = Ellx*E - Ell*Ex;
00063 tmpy = Elly*E - Ell*Ey;
00064 *Cllw = ( Element::E1Sqrt(tmpx*tmpx + tmpy*tmpy) / (E*E) ) * _scale;
00065 }
00066
00067 SrcArithT _scale;
00068 };
00069
00070 template<class ArrayT>
00071 void
00072 MyRestrict(ArrayT* im, int border)
00073 {
00074 im->mBW += border;
00075 im->mBH += border;
00076 im->mCW -= 2*border;
00077 im->mCH -= 2*border;
00078 }
00079
00080 std::vector<Array2dScalarReal64*>
00081 BuildInvCwFeatureList(Array2dVec3Real64* im, double precision, int border)
00082 {
00083 Array2dVec3Real64* imO = 0;
00084 ColorSpace(imO, im, Element::RGB, Element::OOO);
00085
00086 const int nrScales = 3;
00087
00088 double scales[nrScales] = {2.0, 4.0, 8.0};
00089
00090 std::vector<Array2dScalarReal64*> imList;
00091 Array2dScalarReal64* ch = 0;
00092 Array2dScalarReal64* res = 0;
00093 Array2dScalarReal64* E = 0;
00094 Array2dScalarReal64* Ex = 0;
00095 Array2dScalarReal64* Ey = 0;
00096 Array2dScalarReal64* El = 0;
00097 Array2dScalarReal64* Elx = 0;
00098 Array2dScalarReal64* Ely = 0;
00099 Array2dScalarReal64* Ell = 0;
00100 Array2dScalarReal64* Ellx = 0;
00101 Array2dScalarReal64* Elly = 0;
00102
00103 for (int i=0 ; i<nrScales ; i++)
00104 {
00105 ProjectRange(ch, imO, 1);
00106 RecGauss(E, ch, scales[i], scales[i], 0, 0, precision);
00107 RecGauss(Ex, ch, scales[i], scales[i], 1, 0, precision);
00108 RecGauss(Ey, ch, scales[i], scales[i], 0, 1, precision);
00109
00110 ProjectRange(ch, imO, 2);
00111 RecGauss(El, ch, scales[i], scales[i], 0, 0, precision);
00112 RecGauss(Elx, ch, scales[i], scales[i], 1, 0, precision);
00113 RecGauss(Ely, ch, scales[i], scales[i], 0, 1, precision);
00114
00115 ProjectRange(ch, imO, 3);
00116 RecGauss(Ell, ch, scales[i], scales[i], 0, 0, precision);
00117 RecGauss(Ellx, ch, scales[i], scales[i], 1, 0, precision);
00118 RecGauss(Elly, ch, scales[i], scales[i], 0, 1, precision);
00119
00120 M9N4poConFeat<Array2dScalarReal64, Array2dScalarReal64>
00121 mnpoConFeat(scales[i]);
00122 std::vector<Array2dScalarReal64*> fList;
00123 fList = Pattern::PatM9N4PixOp<Array2dScalarReal64>
00124 (E, Ex, Ey, El, Elx, Ely, Ell, Ellx, Elly, mnpoConFeat);
00125 if (border != 0)
00126 {
00127 MyRestrict(fList[0], border);
00128 MyRestrict(fList[1], border);
00129 MyRestrict(fList[2], border);
00130 MyRestrict(fList[3], border);
00131 }
00132
00133 imList.push_back(fList[0]);
00134 imList.push_back(fList[1]);
00135 imList.push_back(fList[2]);
00136 imList.push_back(fList[3]);
00137 }
00138 delete imO;
00139 delete ch;
00140 delete res;
00141 delete E;
00142 delete Ex;
00143 delete Ey;
00144 delete El;
00145 delete Elx;
00146 delete Ely;
00147 delete Ell;
00148 delete Ellx;
00149 delete Elly;
00150 return imList;
00151 }
00152
00153 std::vector<Array2dScalarReal64*>
00154 BuildInvECwFeatureList(Array2dVec3Real64* im, double precision, int border)
00155 {
00156 Array2dVec3Real64* imO = 0;
00157 ColorSpace(imO, im, Element::RGB, Element::OOO);
00158
00159 const int nrScales = 3;
00160 double scales[nrScales] = {1.0, 2.0, 3.5};
00161
00162
00163 std::vector<Array2dScalarReal64*> imList;
00164 Array2dScalarReal64* ch = 0;
00165 Array2dScalarReal64* res = 0;
00166 Array2dScalarReal64* E = 0;
00167 Array2dScalarReal64* Ex = 0;
00168 Array2dScalarReal64* Ey = 0;
00169 Array2dScalarReal64* El = 0;
00170 Array2dScalarReal64* Elx = 0;
00171 Array2dScalarReal64* Ely = 0;
00172 Array2dScalarReal64* Ell = 0;
00173 Array2dScalarReal64* Ellx = 0;
00174 Array2dScalarReal64* Elly = 0;
00175
00176 for (int i=0 ; i<nrScales ; i++)
00177 {
00178 E = 0;
00179 El = 0;
00180 Ell = 0;
00181
00182 ProjectRange(ch, imO, 1);
00183 RecGauss(E, ch, scales[i], scales[i], 0, 0, precision);
00184 RecGauss(Ex, ch, scales[i], scales[i], 1, 0, precision);
00185 RecGauss(Ey, ch, scales[i], scales[i], 0, 1, precision);
00186
00187 ProjectRange(ch, imO, 2);
00188 RecGauss(El, ch, scales[i], scales[i], 0, 0, precision);
00189 RecGauss(Elx, ch, scales[i], scales[i], 1, 0, precision);
00190 RecGauss(Ely, ch, scales[i], scales[i], 0, 1, precision);
00191
00192 ProjectRange(ch, imO, 3);
00193 RecGauss(Ell, ch, scales[i], scales[i], 0, 0, precision);
00194 RecGauss(Ellx, ch, scales[i], scales[i], 1, 0, precision);
00195 RecGauss(Elly, ch, scales[i], scales[i], 0, 1, precision);
00196
00197 M9N4poConFeat<Array2dScalarReal64, Array2dScalarReal64>
00198 mnpoConFeat(scales[i]);
00199 std::vector<Array2dScalarReal64*> fList;
00200 fList = Pattern::PatM9N4PixOp<Array2dScalarReal64>
00201 (E, Ex, Ey, El, Elx, Ely, Ell, Ellx, Elly, mnpoConFeat);
00202 if (border != 0)
00203 {
00204 MyRestrict(E, border);
00205 MyRestrict(El, border);
00206 MyRestrict(Ell, border);
00207 MyRestrict(fList[0], border);
00208 MyRestrict(fList[1], border);
00209 MyRestrict(fList[2], border);
00210 MyRestrict(fList[3], border);
00211 }
00212
00213 imList.push_back(E);
00214 imList.push_back(El);
00215 imList.push_back(Ell);
00216 imList.push_back(fList[0]);
00217 imList.push_back(fList[1]);
00218 imList.push_back(fList[2]);
00219 imList.push_back(fList[3]);
00220 }
00221 delete imO;
00222 delete ch;
00223 delete res;
00224
00225 delete Ex;
00226 delete Ey;
00227
00228 delete Elx;
00229 delete Ely;
00230
00231 delete Ellx;
00232 delete Elly;
00233 return imList;
00234 }
00235
00236 }
00237 }
00238 }
00239
00240 #endif