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

PointDescriptorTable* Impala::Core::Feature::InterestPointFeature::ProjectOntoCodebook ( PointDescriptorTable pointData,
String  codebookMode,
int  imageWidth,
int  imageHeight,
Quid  q 
) [inline, private]

Definition at line 748 of file InterestPointFeature.h.

References Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Add(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get2(), Impala::Core::Feature::GetCodebookLength(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::GetColumn6(), Impala::Core::Feature::PointDescriptorTable::GetDescriptorLength(), Impala::Core::Feature::PointDescriptorTable::GetFeatureDefinition(), Impala::Util::Database::GetFilePath(), Impala::Util::Database::GetIOBuffer(), Impala::Core::Feature::PointDescriptorTable::GetX(), Impala::Core::Feature::PointDescriptorTable::GetY(), ILOG_DEBUG, ILOG_ERROR, Impala::MakeString(), Impala::Core::Matrix::MatNrCol(), Impala::Core::Matrix::MatNrRow(), mCodebook, mDatabase, mDescriptorReduce, mDynamicPointSelector, mDynamicPointSelectorConfig, mLastCodebookVectors, mPointSelector, mStripBorder, ProjectForest(), ProjectHardIndex(), ProjectHardMatrix(), ProjectUNC(), Impala::Core::Array::ReadRaw(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Reserve(), Impala::Core::Feature::PointDescriptorTable::SetDescriptor(), Impala::Core::Feature::PointDescriptorTable::SetDescriptorLength(), and Impala::Core::Table::Table::Size().

Referenced by FindInterestPoints().

00750     {
00759         using namespace Matrix;
00760         ILOG_DEBUG("ProjectOntoCodebook called");
00761         PointDescriptorTable* output = new PointDescriptorTable(
00762                                        pointData->GetFeatureDefinition());
00763         Array::Array2dScalarInt32* tempDynamic = 0;
00764         if(mDynamicPointSelector)
00765         {
00766             // set the point selector configuration based on the image
00767             String filename = "PointSelector/" + mDynamicPointSelectorConfig +
00768                               "/" + MakeString(q) + ".raw";
00769             Util::IOBuffer* buf = 0;
00770             if(mDatabase)
00771             {
00772                 /* translate this name into a complete path */
00773                 filename = mDatabase->GetFilePath(filename, false, false);
00774                 /* read it */
00775                 if(filename.empty())
00776                 {
00777                     ILOG_ERROR("Cannot open dynamic point selector: " << filename);
00778                 }
00779                 buf = mDatabase->GetIOBuffer(filename, true, false, "", 0, true);
00780             }
00781             else
00782             {
00783                 buf = new Util::IOBufferFile(filename, true, true);
00784             }
00785 
00786             // load the selectors from file
00787             ReadRaw(tempDynamic, buf);
00788             delete buf;
00789             for(int i = 0; i < tempDynamic->CH(); i++)
00790             {
00791                 *tempDynamic->CPB(0, i) -= (mStripBorder + 1);
00792                 *tempDynamic->CPB(1, i) -= (mStripBorder + 1);
00793             }
00794             
00795             for(int ps = 0; ps < tempDynamic->CW() - 2; ps++)
00796             {
00797                 mPointSelector.push_back
00798                     (new Geometry::MaskedInterestPointSelector(tempDynamic, ps));
00799             }
00800         }
00801 
00802         std::vector<int> regionCounts;
00803         int codebookLength = mCodebook->Size();
00804         if(codebookMode == "forest")
00805         {
00806             codebookLength = GetCodebookLength(mCodebook);
00807             ILOG_DEBUG("forest codebook length = "<< codebookLength);
00808         }
00809         for(int ps = 0; ps < mPointSelector.size(); ps++)
00810         {
00811             Vector::VectorTem<Real64>* codebookVector = new Vector::VectorTem<Real64>(codebookLength);
00812             for(int i = 0; i < codebookLength; i++)
00813             {
00814                 codebookVector->Elem(i) = 0.0;
00815             }
00816             mLastCodebookVectors.push_back(codebookVector);
00817             regionCounts.push_back(0);
00818         }
00819         ILOG_DEBUG("done making codebook vector");
00820         if(pointData->Size() == 0)
00821         {
00822             delete pointData;
00823             return output;
00824         }
00825         int descriptorLength = pointData->GetDescriptorLength();
00826         std::vector<int> X;
00827         std::vector<int> Y;
00828         X.reserve(pointData->Size());
00829         Y.reserve(pointData->Size());
00830 
00831         ILOG_DEBUG("extracting descriptor data");
00832         for(int it = 0; it < pointData->Size(); it++)
00833         {
00834             X.push_back(static_cast<int>(pointData->GetX(it)));
00835             Y.push_back(static_cast<int>(pointData->GetY(it)));
00836         }
00837 
00838         // dimensionality checks
00839         if((codebookMode != "forest") &&
00840            (mCodebook->Get2(0).Size() != descriptorLength))
00841         {
00842             if(mDescriptorReduce)
00843             {
00844                 if((mCodebook->Get2(0).Size() != MatNrCol(mDescriptorReduce))
00845                    || (descriptorLength != MatNrRow(mDescriptorReduce)))
00846                 {
00847                     ILOG_ERROR("Reduced descriptor dimensionality mismatch");
00848                     throw "bye";
00849                 }
00850             }
00851             else
00852             {
00853                 ILOG_ERROR("ProjectOntoCodebook found visual word"<<
00854                        " and descriptor of different sizes!\n\t\t"<<
00855                        "codebook: "<< mCodebook->Get2(0).Size() <<
00856                        ", descriptor:"<< descriptorLength);
00857                 throw "Dimensionality mismatch!";
00858             }
00859         }
00860 
00861         // create a wrapper with the correct dimensions
00862         Array2dScalarReal64* descriptors = 
00863             new Array2dScalarReal64(descriptorLength, pointData->Size(), 0, 0,
00864             pointData->GetColumn6()->GetStorage()->mData, true);
00865             
00866         ILOG_DEBUG("extracted descriptor data");
00867 
00868         // Visual word uncertainty (UNC)
00869         if(codebookMode == "unc")
00870             ProjectUNC(descriptors, imageWidth, imageHeight, 
00871                        X, Y, regionCounts);
00872         // hard assignment, matrix style
00873         if((codebookMode == "hardmatrix") || (codebookMode == "hard"))
00874             ProjectHardMatrix(descriptors, imageWidth, imageHeight,
00875                               X, Y, regionCounts);
00876         // hard assignment, matrix style, and only output the indices (special)
00877         if(codebookMode == "hardindex")
00878         {
00879             ProjectHardIndex(descriptors, pointData);
00880             delete descriptors;
00881             delete output;
00882             return pointData;
00883         }
00884         if(codebookMode == "forest")
00885             ProjectForest(descriptors, imageWidth, imageHeight,
00886                           X, Y, regionCounts);
00887         delete descriptors;
00888 
00889         // normalize so it sums to one
00890         for(int ps = 0; ps < mPointSelector.size(); ps++)
00891         {
00892             // debugStream << "\n\npyramid part #"<<ps<<"\n";
00893             int regionCount = regionCounts[ps];
00894             ILOG_DEBUG("regCount " << regionCount);
00895             if(regionCount == 0)
00896                 regionCount = 1;
00897             for(int i = 0; i < codebookLength; i++)
00898             {
00899                 mLastCodebookVectors[ps]->Elem(i) =
00900                     mLastCodebookVectors[ps]->Elem(i) / regionCount;
00901             }
00902         }
00903         if(mPointSelector.size() > 0)
00904             output->SetDescriptorLength(codebookLength);
00905         output->Reserve(mPointSelector.size(), false);
00906         for(int ps = 0; ps < mPointSelector.size(); ps++)
00907         {
00908             output->Add(0, 0, 0, 0, 0);
00909             //for(int i = 0; i < codebookLength; i++)
00910             //    std::cout << mLastCodebookVectors[ps]->Elem(i) << " ";
00911             output->SetDescriptor(ps, *(mLastCodebookVectors[ps]));
00912         }
00913 
00914         if(mDynamicPointSelector)
00915         {
00916             for(int ps = 0; ps < mPointSelector.size(); ps++)
00917             {
00918                 delete mPointSelector[ps];
00919             }
00920             mPointSelector.clear();
00921             delete tempDynamic;
00922         }
00923         delete pointData;
00924         return output;
00925     }

Here is the call graph for this function:


Generated on Fri Mar 19 11:10:01 2010 for ImpalaSrc by  doxygen 1.5.1