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

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

Definition at line 1016 of file InterestPointFeature.h.

References Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Add(), Impala::Core::Feature::FeatureTableResult::AddVector(), 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(), GetFeatureName(), Impala::Persistency::File::GetReadBuffer(), Impala::Persistency::File::GetWriteBuffer(), 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, mDescriptorReduce, mDynamicPointSelector, mDynamicPointSelectorConfig, mLocator, mPointSelector, mResultOutput, mStripBorder, Impala::PathJoin(), ProjectForest(), ProjectHardIndex(), ProjectHardMatrix(), ProjectLLC(), ProjectUNC(), Impala::Core::Array::ReadRaw(), Impala::Persistency::RepositoryGetFile(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Reserve(), Impala::Core::Feature::PointDescriptorTable::SetDescriptor(), Impala::Core::Feature::PointDescriptorTable::SetDescriptorLength(), Impala::Core::Table::Table::Size(), Impala::StringReplace(), and Impala::StringStartsWith().

Referenced by FindInterestPoints().

01018     {
01025         using namespace Matrix;
01026         ILOG_DEBUG("ProjectOntoCodebook called");
01027         PointDescriptorTable* output = new PointDescriptorTable(
01028                                        pointData->GetFeatureDefinition());
01029         Array::Array2dScalarInt32* tempDynamic = 0;
01030         if(mDynamicPointSelector)
01031         {
01032             // set the point selector configuration based on the image
01033             String filename = "PointSelector/" + mDynamicPointSelectorConfig +
01034                               "/" + MakeString(quid) + ".raw";
01035             FileLocator loc(mLocator, filename);
01036             File file = RepositoryGetFile(loc, false, false);
01037             Util::IOBuffer* buf = file.GetReadBuffer();
01038 
01039             // load the selectors from file
01040             ReadRaw(tempDynamic, buf);
01041             delete buf;
01042             for(int i = 0; i < tempDynamic->CH(); i++)
01043             {
01044                 *tempDynamic->CPB(0, i) -= (mStripBorder + 1);
01045                 *tempDynamic->CPB(1, i) -= (mStripBorder + 1);
01046             }
01047             
01048             for(int ps = 0; ps < tempDynamic->CW() - 2; ps++)
01049             {
01050                 mPointSelector.push_back
01051                     (new Geometry::MaskedInterestPointSelector(tempDynamic, ps));
01052             }
01053         }
01054 
01055         std::vector<Real64> regionCounts;
01056         int codebookLength = mCodebook->Size();
01057         if(codebookMode == "forest")
01058         {
01059             codebookLength = GetCodebookLength(mCodebook);
01060             ILOG_DEBUG("forest codebook length = "<< codebookLength);
01061         }
01062 
01063         CodebookVectors codebookVectors;
01064         for(int ps = 0; ps < mPointSelector.size(); ps++)
01065         {
01066             Vector::VectorTem<Real64>* codebookVector =
01067                 new Vector::VectorTem<Real64>(codebookLength);
01068             for(int i = 0; i < codebookLength; i++)
01069             {
01070                 codebookVector->Elem(i) = 0.0;
01071             }
01072             codebookVectors.push_back(codebookVector);
01073             regionCounts.push_back(0);
01074         }
01075         ILOG_DEBUG("done making codebook vector");
01076         if(pointData->Size() == 0)
01077         {
01078             if(mResultOutput)
01079             {
01080                 for(int i = 0; i < codebookVectors.size(); i++)
01081                 {
01082                     mResultOutput->AddVector(quid, i, *codebookVectors[i]);
01083                 }
01084             }
01085             delete pointData;
01086             return output;
01087         }
01088         int descriptorLength = pointData->GetDescriptorLength();
01089         std::vector<int> X;
01090         std::vector<int> Y;
01091         X.reserve(pointData->Size());
01092         Y.reserve(pointData->Size());
01093 
01094         ILOG_DEBUG("extracting descriptor data");
01095         for(int it = 0; it < pointData->Size(); it++)
01096         {
01097             X.push_back(static_cast<int>(pointData->GetX(it)));
01098             Y.push_back(static_cast<int>(pointData->GetY(it)));
01099         }
01100 
01101         // dimensionality checks
01102         if((codebookMode != "forest") &&
01103            (mCodebook->Get2(0).Size() != descriptorLength))
01104         {
01105             if(mDescriptorReduce)
01106             {
01107                 if((mCodebook->Get2(0).Size() != MatNrCol(mDescriptorReduce))
01108                    || (descriptorLength != MatNrRow(mDescriptorReduce)))
01109                 {
01110                     ILOG_ERROR("Reduced descriptor dimensionality mismatch");
01111                     throw "bye";
01112                 }
01113             }
01114             else
01115             {
01116                 ILOG_ERROR("ProjectOntoCodebook found visual word"<<
01117                        " and descriptor of different sizes!\n\t\t"<<
01118                        "codebook: "<< mCodebook->Get2(0).Size() <<
01119                        ", descriptor:"<< descriptorLength);
01120                 throw "Dimensionality mismatch!";
01121             }
01122         }
01123 
01124         // create a wrapper with the correct dimensions
01125         Array2dScalarReal64* descriptors = 
01126             new Array2dScalarReal64(descriptorLength, pointData->Size(), 0, 0,
01127             pointData->GetColumn6()->GetStorage()->mData, true);
01128             
01129         ILOG_DEBUG("extracted descriptor data");
01130 
01131         // Visual word uncertainty (UNC)
01132         if(codebookMode == "unc")
01133             ProjectUNC(codebookVectors, descriptors, imageWidth, imageHeight, 
01134                        X, Y, regionCounts);
01135         // hard assignment, matrix style
01136         if((codebookMode == "hardmatrix") || (codebookMode == "hard"))
01137             ProjectHardMatrix(codebookVectors, descriptors, imageWidth, 
01138                               imageHeight, X, Y, regionCounts);
01139         // hard assignment, matrix style, and only output the indices (special)
01140         if(codebookMode == "hardindex")
01141         {
01142             ProjectHardIndex(descriptors, pointData);
01143             delete descriptors;
01144             delete output;
01145             for(int i = 0; i < codebookVectors.size(); i++)
01146                 delete codebookVectors[i];
01147             codebookVectors.clear();
01148             return pointData;
01149         }
01150         if(codebookMode == "forest")
01151             ProjectForest(codebookVectors, descriptors, imageWidth, imageHeight,
01152                           X, Y, regionCounts);
01153         // LLC assignment, dump the indices to disk
01154         if(StringStartsWith(codebookMode, "llcdump"))
01155         {
01156             String folder = "ClusterIndices/" + GetFeatureName();
01157             String filename = PathJoin(folder, MakeString(quid) + ".raw");
01158             FileLocator loc(mLocator, filename);
01159             File file = RepositoryGetFile(loc, true, false);
01160             Util::IOBuffer* buf = file.GetWriteBuffer();
01161             codebookMode = StringReplace(codebookMode, "llcdump", "llc");
01162             ProjectLLC(codebookVectors, codebookMode, descriptors, imageWidth, 
01163                        imageHeight, X, Y, regionCounts, buf);
01164             delete buf;
01165         }
01166         else if(StringStartsWith(codebookMode, "llc"))
01167         {
01168             ProjectLLC(codebookVectors, codebookMode, descriptors, imageWidth,
01169                        imageHeight, X, Y, regionCounts);
01170         }
01171         delete descriptors;
01172 
01173         // normalize so it sums to one (although this is not guaranteed,
01174         // it depends on what the functions called above put into the
01175         // regionCount variable)
01176         for(int ps = 0; ps < mPointSelector.size(); ps++)
01177         {
01178             // debugStream << "\n\npyramid part #"<<ps<<"\n";
01179             Real64 regionCount = regionCounts[ps];
01180             ILOG_DEBUG("regCount " << regionCount);
01181             if(regionCount == 0)
01182                 regionCount = 1;
01183             for(int i = 0; i < codebookLength; i++)
01184             {
01185                 codebookVectors[ps]->Elem(i) =
01186                     codebookVectors[ps]->Elem(i) / regionCount;
01187             }
01188         }
01189         if(mPointSelector.size() > 0)
01190             output->SetDescriptorLength(codebookLength);
01191         output->Reserve(mPointSelector.size(), false);
01192         for(int ps = 0; ps < mPointSelector.size(); ps++)
01193         {
01194             output->Add(0, 0, 0, 0, 0);
01195             //for(int i = 0; i < codebookLength; i++)
01196             //    std::cout << mLastCodebookVectors[ps]->Elem(i) << " ";
01197             output->SetDescriptor(ps, *(codebookVectors[ps]));
01198         }
01199 
01200         if(mResultOutput)
01201         {
01202             for(int i = 0; i < codebookVectors.size(); i++)
01203             {
01204                 mResultOutput->AddVector(quid, i, 
01205                                          *codebookVectors[i]);
01206             }
01207         }
01208 
01209         if(mDynamicPointSelector)
01210         {
01211             for(int ps = 0; ps < mPointSelector.size(); ps++)
01212             {
01213                 delete mPointSelector[ps];
01214             }
01215             mPointSelector.clear();
01216             delete tempDynamic;
01217         }
01218         delete pointData;
01219         return output;
01220     }

Here is the call graph for this function:


Generated on Thu Jan 13 09:19:23 2011 for ImpalaSrc by  doxygen 1.5.1