00001 #ifndef Impala_Core_ImageSet_CombineConcepts_h
00002 #define Impala_Core_ImageSet_CombineConcepts_h
00003
00004 #include "Core/Column/AddAssign.h"
00005 #include "Core/Column/MulAssign.h"
00006 #include "Core/Column/DivAssign.h"
00007 #include "Core/Table/SimilarityTableSet.h"
00008 #include "Core/ImageSet/Reporter.h"
00009
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace ImageSet
00015 {
00016
00017
00018 class CombineConcepts : public Listener
00019 {
00020 public:
00021 typedef Feature::FeatureDefinition FeatureDefinition;
00022 typedef Table::SimilarityTableSet SimilarityTableSet;
00023
00024 CombineConcepts(Reporter* reporter, CmdOptions& options)
00025 {
00026 mReporter = reporter;
00027 if (options.GetNrArg() < 7)
00028 {
00029 ILOG_ERROR("Missing argument");
00030 return;
00031 }
00032 mConceptFileName = options.GetArg(2);
00033 mModel = options.GetArg(3);
00034 mResultName = options.GetArg(4);
00035 mCombi = options.GetArg(5);
00036 if ((mCombi != "mul") && (mCombi != "avg"))
00037 {
00038 ILOG_ERROR("Unknown combination method : " << mCombi);
00039 return;
00040 }
00041 for (int i=6 ; i<options.GetNrArg() ; i++)
00042 mFeatureDefs.push_back(options.GetArg(i));
00043 }
00044
00045 virtual void
00046 HandleNewWalk(ImageSet* is, String walkType)
00047 {
00048 mWalkType = walkType;
00049 }
00050
00051 virtual void
00052 HandleDoneDir(ImageSet* is, int dirId)
00053 {
00054 SimilarityTableSet* combinedSet = 0;
00055 for (int i=0 ; i<mFeatureDefs.size() ; i++)
00056 {
00057 if (combinedSet == 0)
00058 {
00059 combinedSet = SimilarityTableSet::MakeFromFile
00060 (is, mWalkType, mConceptFileName, mModel,
00061 mFeatureDefs[i], dirId);
00062 }
00063 else
00064 {
00065 SimilarityTableSet* simSet = SimilarityTableSet::MakeFromFile
00066 (is, mWalkType, mConceptFileName, mModel, mFeatureDefs[i],
00067 dirId);
00068 for (int t=0 ; t<simSet->NrTables() ; t++)
00069 {
00070 if (mCombi == "mul")
00071 MulAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00072 simSet->GetSimTable(t)->GetColumn1(), 0, -1);
00073 else
00074 AddAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00075 simSet->GetSimTable(t)->GetColumn1(), 0, -1);
00076 }
00077 delete simSet;
00078 }
00079 }
00080 if (mCombi == "avg")
00081 for (int t=0 ; t<combinedSet->NrTables() ; t++)
00082 DivAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00083 mFeatureDefs.size(), 0, -1);
00084 combinedSet->ComputeRanks(true);
00085
00086 combinedSet->Save(is, mWalkType, mConceptFileName, mModel, mResultName,
00087 dirId, true);
00088 delete combinedSet;
00089 }
00090
00091 private:
00092
00093 Reporter* mReporter;
00094 String mConceptFileName;
00095 String mModel;
00096 String mResultName;
00097 String mCombi;
00098 std::vector<String> mFeatureDefs;
00099 String mWalkType;
00100
00101 ILOG_VAR_DEC;
00102
00103 };
00104
00105 ILOG_VAR_INIT(CombineConcepts, Impala.Core.ImageSet);
00106
00107 }
00108 }
00109 }
00110
00111 #endif