00001 #ifndef Impala_Core_Test_TestWeibull_h
00002 #define Impala_Core_Test_TestWeibull_h
00003
00004 #include "Core/Test/TestImage.h"
00005 #include "Core/Geometry/RectanglePyramid.h"
00006 #include "Core/Feature/Weibull.h"
00007 #include "Core/Table/Write.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace Test
00014 {
00015
00016
00017 class TestWeibull : public TestImage
00018 {
00019 public:
00020
00021 TestWeibull(String srcName, double sigma, int binCount, double histExt)
00022 {
00023 mTestNameBase = "Weibull";
00024 mSrcName = srcName;
00025 mSigma = sigma;
00026 mBinCount = binCount;
00027 mHistExt = histExt;
00028 mPyramid = Geometry::RectanglePyramid(15, 2, 6, 4, -1, -1);
00029 }
00030
00031 virtual void
00032 Run()
00033 {
00034 typedef Vector::VectorTem<Real64> VectorReal64;
00035 typedef Histogram::Histogram1dSet<Array2dScalarReal64> HistSetType;
00036 typedef Vector::VectorSet<Array2dScalarReal64> VecSetType;
00037 typedef Feature::FeatureTable FeatureTable;
00038
00039 Array2dVec3UInt8* src = OpenSrcArray(mSrcName);
00040 mPyramid.SetImageSize(src->CW(), src->CH());
00041
00042 Array::ArraySet<Array2dScalarReal64> invSet;
00043 Array::InvWiccest(invSet, src, false, false, mSigma, 3, true);
00044 HistSetType histSet(-mHistExt, mHistExt, mBinCount, invSet.Size());
00045 int vecSize = 2;
00046 Feature::FeatureDefinition def("dummy");
00047 FeatureTable histTab(def, 1000, mBinCount);
00048 FeatureTable weiTab(def, 1000, vecSize);
00049 for (int l=0 ; l<mPyramid.NrLevels() ; l++)
00050 {
00051 for (int r=0 ; r<mPyramid.NrRects(l) ; r++)
00052 {
00053 Geometry::Rectangle rect = mPyramid.Rect(l, r);
00054 Histogram::MakeHistogram1dSet(&histSet, invSet, rect, true);
00055 for (int h=0 ; h<histSet.Size() ; h++)
00056 {
00057 histTab.Add(r, histSet.Hist(h));
00058 VectorReal64 v(vecSize);
00059 Histogram::ComputeWeibull(v, histSet.Hist(h), false, false);
00060 weiTab.Add(r, v);
00061 }
00062 }
00063 }
00064 int id = mImSet->GetFileId(mSrcName);
00065 String histS = FileNameCtor("", mTestNameBase, "histogram", mSigma,
00066 mBinCount, mHistExt, ".tab");
00067 String weiS = FileNameCtor("", mTestNameBase, "weibull", mSigma,
00068 mBinCount, mHistExt, ".tab");
00069 if (1)
00070 {
00071 Compare(&histTab,
00072 mImSet->GetFilePathReference(id, histS, false, false));
00073 Compare(&weiTab,
00074 mImSet->GetFilePathReference(id, weiS, false, false));
00075 }
00076 else
00077 {
00078 Table::Write(&histTab,
00079 mImSet->GetFilePathReference(id, histS, true, false),
00080 mImSet->GetDatabase(), true);
00081 Table::Write(&weiTab,
00082 mImSet->GetFilePathReference(id, weiS, true, false),
00083 mImSet->GetDatabase(), true);
00084 }
00085 invSet.Delete();
00086 delete src;
00087 }
00088
00089 virtual String
00090 Name() const
00091 {
00092 return FileNameCtor(mTestNameBase, mSrcName, mSigma, mBinCount,
00093 mHistExt, "");
00094 }
00095
00096 private:
00097
00098 String mTestNameBase;
00099 String mSrcName;
00100 double mSigma;
00101 int mBinCount;
00102 double mHistExt;
00103 Geometry::RectanglePyramid mPyramid;
00104
00105 };
00106
00107
00108 static TestBase* gWeibullSuite[] =
00109 {
00110 new TestWeibull("giraffe.png", 1.0, 1000, 1.0),
00111 new TestWeibull("giraffe.png", 1.0, 1001, 1.0),
00112 new TestWeibull("giraffe.png", 3.0, 1000, 1.0),
00113 new TestWeibull("giraffe.png", 3.0, 1001, 1.0),
00114 (TestBase*)0
00115 };
00116
00117 }
00118 }
00119 }
00120
00121 #endif