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

void Impala::Core::KeyPoint::DoG::LocalizeKeypoints (  )  [inline]

Definition at line 245 of file DoG.h.

References Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get1(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get2(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get3(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get4(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get5(), Impala::Core::Array::Octaves::GetOctave(), ILOG_INFO, Impala::Core::Array::Octaves::IsResamplingEnabled(), mCancelled, Impala::Core::KeyPoint::Detector::mKeyPoints, mOctaves, Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Set2(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Set3(), Impala::Application::DemoCamera2d::sigma, and Impala::Core::Table::Table::Size().

Referenced by FindKeyPoints().

00246     {   
00247         int k = 0 ;
00248         int OrigSize=mKeyPoints->Size();
00249         ILOG_INFO("Localizing "<<OrigSize<<" Keypoints");
00250         int new_i;
00251         int new_j;
00252         int last=0;
00253         int count=0;
00254         mCancelled=0;
00255         double H[4];
00256         double G[2];
00257         double S[2];
00258         Real64 Dx=0;
00259         Array2dScalarReal64* Octave;
00261         //form the Hessian matrix &Gradient vector around each point, 
00262         //and find the shift from 
00263         // -inv((Hessian(A))*Grad(A)) : evaluated at the keypoint
00264         while(k<OrigSize)
00265         {
00266             Real64 sigma=mKeyPoints->Get1(k);
00267             int i = mKeyPoints->Get2(k);
00268             int j = mKeyPoints->Get3(k);
00269             int o = mKeyPoints->Get4(k);
00270             int l = mKeyPoints->Get5(k);
00271 
00272 
00273             Octave=mOctaves->GetOctave(o,l);
00274 
00275             int Width=mOctaves->GetOctave(o,l)->CW();
00276             int Height=mOctaves->GetOctave(o,l)->CH();
00277 
00278 
00279             //dd stands for derivative distance..something I just made up now-)
00280             int dd;
00281 
00283             // If resampling is enabled, we have already reduced 
00284             // the scale by two at every octave(doubling of sigma). 
00285             // Therefore the derivative is the immediate neighbors.
00286             //
00287             // Otherwise we have to jump as much as one sigma for a derivative,
00288             // since the images are not scaled down as well.
00289             if(mOctaves->IsResamplingEnabled())
00290                 dd=1;
00291             else
00292                 dd=sigma;
00293                 
00294             //ILOG_DEBUG("Using "<<dd<<" as der.distance @ ("<<o<<","<<l<<")");
00295             if((i+2*dd>=Width)||(j+2*dd>=Height)||(i-2*dd<0)||(j-2*dd<0))
00296             {
00297                 //ILOG_WARN("Should cancel the keypoint");
00298                 mCancelled++;
00299                 mKeyPoints->Set2(k,0);
00300                 mKeyPoints->Set3(k,0);
00301                 count=0;
00302                 k++;
00303                 last=k;
00304                 continue;
00305             }
00306                 
00307         
00308 
00309             //Second row of Hessian
00310             //this is the first derivative wrt. x
00311             //[ -1 0 1 ]
00312             G[0] = Octave->Value(i+dd,j) - Octave->Value(i-dd,j);
00313 
00314 
00315             //second derivative wrt. x
00316             //[ 1 0 -2 0 1 ]
00317             H[0]= -2*Octave->Value(i,j)  +
00318                     Octave->Value(i-2*dd,j) +
00319                     Octave->Value(i+2*dd,j) ;
00320             /* Second Derivative
00321             [ 1  0 -1]
00322             [ 0  0  0]
00323             [-1  0  1]*/
00324             //second derivative wrt. y
00325             H[1]=    Octave->Value(i-dd,j-dd) +
00326                      Octave->Value(i+dd,j+dd) -
00327                      Octave->Value(i-dd,j+dd) -
00328                      Octave->Value(i+dd,j-dd) ;
00329 
00330             //Third row of Hessian
00331             //this is the first derivative wrt. y
00332             G[1] = Octave->Value(i,j+dd) - Octave->Value(i,j-dd);
00333 
00334             //second derivative wrt. y
00335             //[ 1 0 -2 0 1 ]
00336             H[2]= -2*Octave->Value(i,j)  +
00337                     Octave->Value(i,j-2*dd) +
00338                     Octave->Value(i,j+2*dd) ;
00339 
00340             /* Second Derivative
00341             [ 1  0 -1]
00342             [ 0  0  0]
00343             [-1  0  1]*/
00344             //second derivative wrt. y
00345             H[3]=   Octave->Value(i-dd,j-dd) +  Octave->Value(i+dd,j+dd) -
00346                     Octave->Value(i-dd,j+dd) -  Octave->Value(i+dd,j-dd) ;
00347 
00348             Real64 div = H[0]*H[3]-H[1]*H[2];
00349             S[0]=(-H[3]*G[0]+H[1]*G[1])/div;
00350             S[1]=(H[2]*G[0]-H[0]*G[1])/div;
00351     
00352             Dx= Octave->Value(i,j)+.5*(S[0]*G[0]+S[1]+G[1]);
00353             if(Dx<.03){
00354                 //ILOG_WARN("Should cancel the keypoint");
00355                 mCancelled++;
00356                 mKeyPoints->Set2(k,0);
00357                 mKeyPoints->Set3(k,0);
00358                 count=0;
00359                 k++;
00360                 last=k;
00361                 continue;
00362             }
00363             //advance to the next keypoint
00364             if(!((S[0]> 0.5)||(S[1]> 0.5)||(S[0]<-.5)||(S[1]<-.5))){
00365                k++;
00366                last=k;
00367                count=0;
00368             }else{
00369                 new_i=i+S[0];
00370                 new_j=j+S[1];
00371                 if((new_i>0)&&(new_i<Width)){
00372                     mKeyPoints->Set2(k,new_i);
00373                 }else{
00374                     //ILOG_INFO("Keypoint "<<k<<" : Location out of border");
00375                     count=0;
00376                     k++;
00377                     last=k;
00378                     continue;
00379                 }
00380 
00381 
00382                 if((new_j>0)&&(new_j<Height)){
00383                     mKeyPoints->Set3(k,new_j);
00384                 }else{
00385                     //ILOG_INFO("Keypoint "<<k<<" : Location out of border");
00386                     count=0;
00387                     k++;
00388                     last=k;
00389                     continue;
00390                 }
00391 
00392                 if(last==k)
00393                     count++;
00394                 /*
00395                 ILOG_DEBUG("Keypoint "<<k<<" : Location shifted!("<<count<<")");
00396                 ILOG_DEBUG("Estimated Shift : "<<S[0]<<"x"<<S[1]);
00397                 */
00398 
00399                 if(count>10){
00400                     k++;
00401                     last=k;
00402                     count=0;
00403                 }
00404             }
00405 
00406         }
00407         ILOG_INFO("Cancel count:"<<mCancelled<<"/"<<OrigSize);
00408 
00409     }

Here is the call graph for this function:


Generated on Thu Jan 13 09:20:10 2011 for ImpalaSrc by  doxygen 1.5.1