00001 #ifndef Impala_Core_Feature_Test_TestFunctions_h
00002 #define Impala_Core_Feature_Test_TestFunctions_h
00003
00004 #include <cppunit/extensions/HelperMacros.h>
00005
00006 #include "Core/Feature/Surf.h"
00007 #include "Core/Feature/HaarResponse.h"
00008 #include "Core/Array/SetVal.h"
00009 #include "Core/Array/IntegrateReduce.h"
00010 #include "Core/Array/MakeIntegral.h"
00011
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace Feature
00017 {
00018
00024 class TestFunctions : public CPPUNIT_NS::TestFixture
00025 {
00026 CPPUNIT_TEST_SUITE(TestFunctions);
00027 CPPUNIT_TEST(testIntegralImage);
00028 CPPUNIT_TEST(testReducedImage);
00029 CPPUNIT_TEST(testReducedImageWeighted);
00030 CPPUNIT_TEST(testHaar);
00031
00032 CPPUNIT_TEST_SUITE_END();
00033
00034 public:
00035
00036 void
00037 setUp()
00038 {
00039 mImage = new Array::Array2dScalarReal64(10,10,0,0);
00040 SetVal(mImage, 0.);
00041 double* ptr = mImage->CPB();
00042 ptr[22] = 1.0;
00043 ptr[27] = 0.5;
00044 mIntegral = Array::MakeIntegral(mImage);
00045 mReduced = 0;
00046 Array::IntegrateReduce(mReduced, mImage, 4);
00047 }
00048
00049 void
00050 tearDown()
00051 {
00052 delete mImage;
00053 delete mIntegral;
00054 }
00055
00056 void
00057 testIntegralImage()
00058 {
00059 CPPUNIT_ASSERT(mIntegral != 0);
00060 CPPUNIT_ASSERT_EQUAL(10, (int) mIntegral->CW());
00061 CPPUNIT_ASSERT_EQUAL(10, (int) mIntegral->CH());
00062 CPPUNIT_ASSERT_EQUAL(0.0, mIntegral->Value(0, 0));
00063 CPPUNIT_ASSERT_EQUAL(1.0, mIntegral->Value(5, 5));
00064 CPPUNIT_ASSERT_EQUAL(1.5, mIntegral->Value(9, 9));
00065 }
00066
00067 void
00068 testReducedImage()
00069 {
00070 CPPUNIT_ASSERT(mReduced != 0);
00071 CPPUNIT_ASSERT_EQUAL(2, (int) mReduced->CW());
00072 CPPUNIT_ASSERT_EQUAL(2, (int) mReduced->CH());
00073 CPPUNIT_ASSERT_EQUAL(1.0, mReduced->Value(0, 0));
00074 CPPUNIT_ASSERT_EQUAL(0.5, mReduced->Value(1, 0));
00075 CPPUNIT_ASSERT_EQUAL(0.0, mReduced->Value(1, 1));
00076 }
00077
00078
00079 void
00080 testReducedImageWeighted()
00081 {
00082 Array::Array2dScalarReal64* reduced=0;
00083 Array::IntegrateReduceWeighted(reduced, mImage, 4);
00084 CPPUNIT_ASSERT(reduced != 0);
00085 CPPUNIT_ASSERT_EQUAL(2, (int) reduced->CW());
00086 CPPUNIT_ASSERT_EQUAL(2, (int) reduced->CH());
00087 CPPUNIT_ASSERT_EQUAL(1.0, reduced->Value(0, 0));
00088 CPPUNIT_ASSERT_EQUAL(0.5 * 0.67, reduced->Value(1, 0));
00089 CPPUNIT_ASSERT_EQUAL(0.0, reduced->Value(1, 1));
00090 delete reduced;
00091 }
00092
00093 void
00094 testHaar()
00095 {
00096 std::vector<Array::Array2dScalarReal64*> haar;
00097 haar = HaarResponse(mReduced);
00098 CPPUNIT_ASSERT_EQUAL(4, (int) haar.size());
00099 CPPUNIT_ASSERT_EQUAL(1, (int) haar[0]->CW());
00100 CPPUNIT_ASSERT_EQUAL(1, (int) haar[0]->CH());
00101 CPPUNIT_ASSERT_EQUAL(-0.5, haar[0]->Value(0,0));
00102 CPPUNIT_ASSERT_EQUAL(-1.5, haar[1]->Value(0,0));
00103 }
00104
00105 void
00106 testSurf()
00107 {
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 }
00119
00120 private:
00121 Array::Array2dScalarReal64* mImage;
00122 Array::Array2dScalarReal64* mIntegral;
00123 Array::Array2dScalarReal64* mReduced;
00124 ILOG_VAR_DECL;
00125 };
00126
00127 ILOG_VAR_INIT(TestFunctions, Impala.Core.Feature);
00128
00129 CPPUNIT_TEST_SUITE_REGISTRATION( TestFunctions );
00130
00131 }
00132 }
00133 }
00134
00135 #endif
00136