Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

LaplacianDetector.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Feature_LaplacianDetector_h
00002 #define Impala_Core_Feature_LaplacianDetector_h
00003 
00004 #include "Basis/Timer.h"
00005 #include "Core/Array/Laplacian.h"
00006 #include "Core/Feature/PointDescriptorTable.h"
00007 #include "Core/Table/Sort.h"
00008 
00009 
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace Feature
00015 {
00016 
00017     
00018 template<class SrcArrayT>
00019 PointDescriptorTable*
00020 LaplacianDetection(SrcArrayT* imIntensity, 
00021                    bool useRecGauss, Real64 precision) 
00022 {
00023     ILOG_VAR(Core.Feature.LaplacianDetection);
00024     PointDescriptorTable* output = new PointDescriptorTable();
00025     using namespace Impala::Core::Array;
00026     std::vector<Real64> precomputeScales;
00027     std::vector<Array2dScalarReal64*> cache;
00028     for(int i = 0; i < 21; i++) 
00029     {
00030         Real64 sigma = pow(sqrt(sqrt(Real64(2))),i) * 0.8;
00031         precomputeScales.push_back(sigma);
00032         Array2dScalarReal64* tmp = 0;
00033         Laplacian(tmp, imIntensity, sigma, 1, useRecGauss, precision);
00034         cache.push_back(tmp);
00035 
00036         ILOG_DEBUG("Computing Laplacian scale: " << sigma);
00037     }
00038     
00039     int borderIgnoreSize = 5;
00040     for(int i = 1; i < 20; i++) 
00041     {
00042         Array2dScalarReal64* imPrev = cache[i-1]; 
00043         Array2dScalarReal64* im     = cache[i];
00044         Array2dScalarReal64* imNext = cache[i+1];
00045         for(int x = borderIgnoreSize; x < im->CW() - borderIgnoreSize; x++)
00046         {
00047             for(int y = borderIgnoreSize; y < im->CH() - borderIgnoreSize; y++)
00048             {
00049                 Real64 v = im->Val(x, y);
00050                 if(fabs(v) < 0.001) continue;
00051                 if((v >= im->Val(x, y+1)) &&
00052                    (v >= im->Val(x+1, y)) &&
00053                    (v >= im->Val(x, y-1)) &&
00054                    (v >= im->Val(x-1, y)) &&
00055                    (v >= im->Val(x+1, y+1)) &&
00056                    (v >= im->Val(x-1, y-1)) &&
00057                    (v >= im->Val(x-1, y+1)) &&
00058                    (v >= im->Val(x+1, y-1)) &&
00059                    (v >= imPrev->Val(x, y)) &&
00060                    (v >= imPrev->Val(x, y+1)) &&
00061                    (v >= imPrev->Val(x+1, y)) &&
00062                    (v >= imPrev->Val(x, y-1)) &&
00063                    (v >= imPrev->Val(x-1, y)) &&
00064                    (v >= imPrev->Val(x+1, y+1)) &&
00065                    (v >= imPrev->Val(x-1, y-1)) &&
00066                    (v >= imPrev->Val(x-1, y+1)) &&
00067                    (v >= imPrev->Val(x+1, y-1)) &&
00068                    (v >= imNext->Val(x, y)) &&
00069                    (v >= imNext->Val(x, y+1)) &&
00070                    (v >= imNext->Val(x+1, y)) &&
00071                    (v >= imNext->Val(x, y-1)) &&
00072                    (v >= imNext->Val(x-1, y)) &&
00073                    (v >= imNext->Val(x+1, y+1)) &&
00074                    (v >= imNext->Val(x-1, y-1)) &&
00075                    (v >= imNext->Val(x-1, y+1)) &&
00076                    (v >= imNext->Val(x+1, y-1)))
00077                 {
00078                     // found one
00079                     output->Add(x, y, precomputeScales[i], 0, v);
00080                 } else if((v <= im->Val(x, y+1)) &&
00081                    (v <= im->Val(x+1, y)) &&
00082                    (v <= im->Val(x, y-1)) &&
00083                    (v <= im->Val(x-1, y)) &&
00084                    (v <= im->Val(x+1, y+1)) &&
00085                    (v <= im->Val(x-1, y-1)) &&
00086                    (v <= im->Val(x-1, y+1)) &&
00087                    (v <= im->Val(x+1, y-1)) &&
00088                    (v <= imPrev->Val(x, y)) &&
00089                    (v <= imPrev->Val(x, y+1)) &&
00090                    (v <= imPrev->Val(x+1, y)) &&
00091                    (v <= imPrev->Val(x, y-1)) &&
00092                    (v <= imPrev->Val(x-1, y)) &&
00093                    (v <= imPrev->Val(x+1, y+1)) &&
00094                    (v <= imPrev->Val(x-1, y-1)) &&
00095                    (v <= imPrev->Val(x-1, y+1)) &&
00096                    (v <= imPrev->Val(x+1, y-1)) &&
00097                    (v <= imNext->Val(x, y)) &&
00098                    (v <= imNext->Val(x, y+1)) &&
00099                    (v <= imNext->Val(x+1, y)) &&
00100                    (v <= imNext->Val(x, y-1)) &&
00101                    (v <= imNext->Val(x-1, y)) &&
00102                    (v <= imNext->Val(x+1, y+1)) &&
00103                    (v <= imNext->Val(x-1, y-1)) &&
00104                    (v <= imNext->Val(x-1, y+1)) &&
00105                    (v <= imNext->Val(x+1, y-1)))
00106                 {
00107                     // found one
00108                     output->Add(x, y, precomputeScales[i], 0, v);
00109                 }
00110             }
00111         }
00112     }
00113     for(int i = 0; i < cache.size(); i++) 
00114     {
00115         delete cache[i];
00116     }
00117     return output;
00118 }
00119 
00120 
00121 template<class SrcArrayT>
00122 PointDescriptorTable*
00123 LaplacianDetector(SrcArrayT* input, 
00124                   bool useRecGauss=true, Real64 precision=3.0)
00125 {
00126     ILOG_VAR(Core.Feature.LaplacianDetector);
00127     using namespace Impala::Core::Array;
00128     Timer timer;
00129 
00130     // convert to grey-scale
00131     Array2dScalarReal64* imIntensity = 0;
00132     RGB2Gray(imIntensity, input);
00133     
00134     // Laplacian scale selection
00135     PointDescriptorTable* output = LaplacianDetection(imIntensity,
00136                                                       useRecGauss, precision);
00137 
00138     ILOG_INFO("Laplacian detector found " << output->Size() << " points; " << 
00139               timer.SplitTimeStr());
00140 
00141     delete imIntensity;
00142 
00143     // removing double points should not be needed for the Laplacian
00144     //outputPointList.sort(compare_InterestCircle);
00145     //outputPointList.unique(uniq_InterestCircle);
00146     
00147     //ILOG_INFO("Unique operator left " << outputPointList.size() << " points" << timer.SplitTimeStr());
00148     
00149     // now sort the points by cornerness
00150     SortOnColumn5(output, false);
00151     return output;
00152 }
00153 
00154 } // namespace Feature
00155 } // namespace Core
00156 } // namespace Impala
00157 
00158 #endif

Generated on Thu Jan 13 09:04:25 2011 for ImpalaSrc by  doxygen 1.5.1