00001 #ifndef Impala_Core_ImageSet_Color64Extractor_h
00002 #define Impala_Core_ImageSet_Color64Extractor_h
00003
00004
00005
00006
00007 #include "Core/ImageSet/Reporter.h"
00008 #include "Core/Vector/VectorTem.h"
00009 #include "Core/Feature/FeatureTable.h"
00010 #include "Core/Feature/Color64.h"
00011
00012
00013
00014 namespace Impala
00015 {
00016 namespace Core
00017 {
00018 namespace ImageSet
00019 {
00020
00021 class Color64Extractor : public Listener
00022 {
00023
00024 protected:
00025
00026 typedef Vector::VectorTem<Real64> VectorReal64;
00027
00028 public:
00029
00030 Color64Extractor(Reporter* reporter,
00031 CmdOptions& options, CString featureName, int binCount)
00032 {
00033 mReporter = reporter;
00034 mFeatureName = featureName;
00035 mBinCount = binCount;
00036 Feature::FeatureDefinition def(GetFeatureName());
00037 mHistogramTable = new Feature::FeatureTable(def, 1000, GetBinCount());
00038
00039 m_verbose = FALSE;
00040 m_verbose2 = FALSE;
00041 }
00042
00043 Color64Extractor(Reporter* reporter, CmdOptions& options)
00044 {
00045 mReporter = reporter;
00046 mFeatureName = "color64";
00047 mBinCount = 64;
00048 Feature::FeatureDefinition def(GetFeatureName());
00049 mHistogramTable = new Feature::FeatureTable(def, 1000, GetBinCount());
00050
00051 m_verbose = FALSE;
00052 m_verbose2 = FALSE;
00053
00054
00055
00056 }
00057
00058 virtual
00059 ~Color64Extractor()
00060 {
00061 delete mHistogramTable;
00062 }
00063
00064 String
00065 GetFeatureName() const
00066 {
00067 return mFeatureName;
00068 }
00069
00070 virtual void
00071
00072 HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im)
00073 {
00074 if (!im)
00075 {
00076 ILOG_ERROR("Couldn't load image for fileId " << fileId);
00077 return;
00078 }
00079
00080 if (m_verbose)
00081 {
00082 std::cout << "Current File No. = " << fileId << std::endl;
00083 }
00084
00085 #ifdef __BITMAP_FUNC__
00086 Core::Feature::Bitmap bitmap;
00087 bitmap.SaveRgb2BitmapFile("rgb_Color64Extractor.bmp", im->CPB(), im->CW(), im->CH());
00088
00089 Impala::String fName = "rgb_Color64Extractor.png";
00090 Array::WritePng(im, fName, is->GetDatabase());
00091 #endif
00092
00093 VectorReal64 histogram(mBinCount);
00094
00095 Core::Feature::Color64* pExtractor = new Core::Feature::Color64(mFeatureName);
00096 pExtractor->Extract(im, histogram);
00097
00098 Quid quid = is->GetQuidImage(fileId);
00099 mHistogramTable->Add(quid, histogram);
00100
00101 delete pExtractor;
00102
00103 ILOG_DEBUG("... done file " << fileId);
00104
00105 }
00106
00107 virtual void
00108
00109 HandleDoneDir(ImageSet* is, int dirId)
00110 {
00111 bool binary = true;
00112 Feature::FeatureDefinition def = mHistogramTable->GetFeatureDefinition();
00113
00114 std::string fName = is->GetFilePathFeatureData(def, dirId, false, -1, true, false);
00115
00116 if (!fName.empty())
00117 Table::Write(mHistogramTable, fName, is->GetDatabase(), binary);
00118 mHistogramTable->SetSize(0);
00119
00120 ILOG_DEBUG("... done dir " << dirId);
00121 }
00122
00123 protected:
00124
00125 int
00126 GetBinCount() const
00127 {
00128 return mBinCount;
00129 }
00130
00131 private:
00132
00133
00134
00135 Reporter* mReporter;
00136 String mFeatureName;
00137 int mBinCount;
00138 Feature::FeatureTable* mHistogramTable;
00139
00140 BOOL m_verbose;
00141 BOOL m_verbose2;
00142
00143 ILOG_VAR_DECL;
00144 };
00145
00146 ILOG_VAR_INIT(Color64Extractor, Impala.Core.ImageSet);
00147
00148 }
00149 }
00150 }
00151
00152 #endif