00001 #ifndef Impala_Core_Array_Octaves_h
00002 #define Impala_Core_Array_Octaves_h
00003
00004 #include "Core/Array/Set.h"
00005 #include "Core/Array/Sub.h"
00006 #include "Core/Array/Add.h"
00007 #include "Core/Array/LocalMinMax.h"
00008 #include "Core/Array/Scale.h"
00009 #include "Core/Array/Rotate.h"
00010 #include "Core/Array/PixMinMax.h"
00011 #include "Core/Array/Mul.h"
00012 #include "Core/Array/MulVal.h"
00013 #include "Core/Array/AddVal.h"
00014 #include "Core/Array/WritePng.h"
00015 #include "Core/Array/GaussDerivative.h"
00016 #include "Core/Array/RecGauss.h"
00017 #include "Core/Array/MakeRoi.h"
00018 #include "Core/Array/MakeGaussian2d.h"
00019 #include "Core/Array/Array2dTem.h"
00020 #include "Core/Array/PrintData.h"
00021
00022 #include "Core/Feature/FeatureTable.h"
00023
00024 #include "Core/Histogram/Histogram1dTem.h"
00025 #include "Core/Histogram/MakeHistogram1d.h"
00026
00027 #include "Core/Array/RecGauss.h"
00028 #include "Core/Matrix/MatMulVec.h"
00029
00030
00031
00032 #include "Core/Table/TableTem.h"
00033 #include "Core/Column/ColumnTem.h"
00034 #include <math.h>
00035
00036 #ifndef PI
00037 #define PI 3.14159265358979324
00038 #endif
00039
00040
00041
00042
00043 namespace Impala{
00044 namespace Core{
00045 namespace Array{
00047
00048
00049
00050
00051
00052
00053
00054 class Octaves{
00055 public:
00056
00057 private:
00058 ILOG_VAR_DEC;
00059 Impala::Real64 mSigma0;
00060 Impala::Real64 mSigmaN;
00061 int mOctaves;
00062 int mMinOctave;
00063 int mLevels;
00064 int mScales;
00065 double * mSigmas;
00066 double mSigmaK;
00067 Array2dVec3Real64* mSrcVec3;
00068 Array2dScalarReal64* mSrcScalar;
00069 Array2dScalarReal64** mOctaveArray;
00070 Array2dScalarReal64** mSrcArray;
00071
00072
00073 bool mRecGauss;
00074 bool mResample;
00075 bool mRecursive;
00076
00077 public:
00078 Octaves(Array2dScalarUInt8* src, int Octaves, int Levels, int MinOctave=0)
00079 : mOctaves(Octaves),
00080 mMinOctave(MinOctave),
00081 mLevels(Levels),
00082 mRecGauss(true),
00083 mRecursive(true),
00084 mSrcScalar(0)
00085 {
00086 CmdOptions& options = CmdOptions::GetInstance();
00087 mRecGauss=options.GetBool("recGauss",false);
00088 mResample=options.GetBool("resample",false);
00089 mRecursive=options.GetBool("recursive",false);
00090
00091
00092 ILOG_INFO("Using RecGauss : "<<(mRecGauss?"yes":"no"));
00093 ILOG_INFO("Using Resampling: "<<(mResample?"yes":"no"));
00094 ILOG_INFO("All Recursive : "<<(mRecursive?"yes":"no"));
00095
00096 Real64 min,max;
00097 Set(mSrcScalar,src);
00098 PixMinMax(src,&min,&max);
00099 ILOG_INFO("Input image Min-Max:"<<min<<" "<<max);
00100 Normalize(mSrcScalar);
00101 PixMinMax(mSrcScalar,&min,&max);
00102 ILOG_INFO("Input image Min-Max:"<<min<<" "<<max);
00103 Init();
00104 }
00105 ~Octaves(){
00106 delete [] mSigmas;
00107
00108 for(int i=0;i<mScales*mOctaves;i++)
00109 delete mOctaveArray[i];
00110 delete [] mOctaveArray;
00111
00112 for(int i=0;i<mOctaves;i++)
00113 delete mSrcArray[i];
00114 delete [] mSrcArray;
00115
00116
00117 }
00118 void Normalize(Array2dScalarReal64* s){
00119 Real64 min,max;
00120 PixMinMax(s,&min,&max);
00121 AddVal(s,s,-min);
00122 MulVal(s,s,1/(max-min));
00123 }
00124
00125 int GetOctaveCount(){
00126 return mOctaves;
00127 }
00128
00129 int GetLevelCount(){
00130 return mLevels;
00131 }
00132
00133 int GetScaleCount(){
00134 return mScales;
00135 }
00136
00137 void Init(){
00139
00140
00141
00142 if(mOctaves<1)
00143 {
00144 mOctaves = Max(1,
00145 int(std::floor(log2(Min(mSrcScalar->CW(),mSrcScalar->CH())))
00146 - mMinOctave - 3));
00147 }
00149
00150
00151
00152 mScales=mLevels+3;
00153
00154 ILOG_INFO("Initializing "<<mOctaves
00155 <<" octaves, each with "<<mLevels<<" levels and "
00156 <<mScales<<" scales.");
00157 ILOG_INFO((mResample?"Resampling Enabled":"Resampling Disabled"));
00158
00159
00160 mSigmas = new double[mOctaves*mScales];
00162 mOctaveArray = new Array2dScalarReal64*[mOctaves*mScales];
00163 for(int i=0;i<mOctaves*mScales;i++)
00164 mOctaveArray[i]=0;
00165
00167
00168
00169
00170
00171 mSrcArray = new Array2dScalarReal64*[mOctaves];
00172 for(int i=0;i<mOctaves;i++)
00173 mSrcArray[i]=0;
00174
00175
00176 ILOG_INFO("Octave structures constructed!");
00177 BuildOctave();
00178 ILOG_INFO("Octave structures initialized!");
00179
00180
00181 }
00182
00183 void BuildOctave(){
00185
00186
00187
00188
00189 mSigmas[0] = 1;
00190
00191 for(int o=1;o<mOctaves;o++)
00192 {
00193 mSigmas[o*mScales] = 2 * mSigmas[(o-1)*mScales];
00194 }
00195
00197
00198 mSigmaK = powf(2.0,1.0/mLevels);
00199
00201
00202
00203
00204 for(int o=0;o<mOctaves;o++){
00205 std::ostringstream oss;
00206 oss<<"Octave "<<o<<" :";
00207 for(int l=0;l<mScales;l++)
00208 {
00209 mSigmas[o*mScales+l] = mSigmas[o*mScales] * powf(mSigmaK,l);
00210 oss<<" "<< mSigmas[o*mScales+l];
00211 }
00212 ILOG_INFO(oss.str());
00213 }
00214
00216
00217
00218 for(int o=0;o<mOctaves;o++)
00219 {
00220
00221
00222
00223
00224 if(mResample)
00225 {
00226 if((o==0))
00227 {
00228
00229 mSrcArray[o] = 0;
00230 Scale(mSrcArray[o], mSrcScalar,2,2,Geometry::LINEAR);
00231
00232 }else{
00233
00234
00235 Array2dScalarReal64* src=mOctaveArray[(o-1)*mScales+mLevels];
00236 mSrcArray[o] = 0;
00237 Scale(mSrcArray[o],src,.5,.5,Geometry::NEAREST);
00238 }
00239 }
00240 else
00241 {
00243
00244
00245 if(o==0){
00246 mSrcArray[o] = 0;
00247 Set(mSrcArray[o], mSrcScalar);
00248 }else{
00249 mSrcArray[o] = 0;
00250 Set(mSrcArray[o],mOctaveArray[(o-1)*mScales+mLevels]);
00251 }
00252
00253 }
00255
00256
00257
00258
00259 for(int l=0;l<mScales;l++)
00260 {
00261
00262 if(mRecGauss)
00263 {
00264 if(mRecursive)
00265 {
00266
00267 Array2dScalarReal64* src;
00269
00270
00271
00272 if(l==0)
00273 src = mSrcArray[o];
00274 else
00275 src = mOctaveArray[o*mScales+l-1];
00276
00277 RecGauss(mOctaveArray[o*mScales+l],
00278 src,
00279 mSigmaK,
00280 mSigmaK,0,0,3);
00281 }else{
00282
00283
00284 RecGauss(mOctaveArray[o*mScales+l],
00285 mSrcArray[o],
00286 mSigmas[l],
00287 mSigmas[l],
00288 0,0,3);
00289
00290 }
00291 }
00292 else
00293 {
00294 if(mRecursive)
00295 {
00296 Array2dScalarReal64* src;
00297 if(l==0)
00298 src = mSrcArray[o];
00299 else
00300 src = mOctaveArray[o*mScales+l-1];
00301
00302 GaussDerivative(mOctaveArray[o*mScales+l],
00303 src,
00304 mSigmaK,0,0,3);
00305
00306 }else{
00307 GaussDerivative(mOctaveArray[o*mScales+l],
00308 mSrcArray[o],
00309 mSigmas[l],
00310 0,0,3);
00311 }
00312 }
00313 Real64 min=0;
00314 Real64 max=0;
00315 PixMinMax(mOctaveArray[o*mScales+l],&min,&max);
00316
00317 }
00318 }
00319 }
00320
00321 Array2dScalarReal64* GetOctave(int o,int l)
00322 {
00323 return mOctaveArray[o*mScales+l];
00324 }
00325
00326
00327 double GetSigma(int o, int l){
00328 return mSigmas[o*mScales+l];
00329 }
00330 bool IsResamplingEnabled(){
00331 return mResample;
00332 }
00333
00334 };
00335 ILOG_VAR_INIT(Octaves, Impala.Core.Array);
00336
00337 }}}
00338
00339
00340
00341 #endif
00342
00343