00001
00016 #ifndef MDS_TRIFEATURES_H
00017 #define MDS_TRIFEATURES_H
00018
00019 #include "mdsTriBase.h"
00020 #include "mdsTriData.h"
00021
00022
00023 #include <MDSTk/Base/mdsGlobalLog.h>
00024 #include <MDSTk/Math/mdsStaticVector.h>
00025
00026
00027 #include <VectorEntity/mcentity.h>
00028
00029
00030 namespace mds
00031 {
00032 namespace seg
00033 {
00034
00036
00037
00039
00040
00042
00043
00045
00046
00047
00048
00049
00050
00051
00052
00053 namespace TriFeatures
00054 {
00055
00057 #ifdef USE_VARIANCE
00058 const int NUM_OF_BASIC_FEATURES = 2;
00059 #else
00060 const int NUM_OF_BASIC_FEATURES = 1;
00061 #endif // USE_VARIANCE
00062
00064 #ifdef USE_LOCAL_MOMENTS
00065 const int NUM_OF_MOMENTS = 21;
00066 #else
00067 const int NUM_OF_MOMENTS = 0;
00068 #endif // USE_LOCAL_MOMENTS
00069
00071 #ifdef USE_HARALICK_FEATURES
00072 const int NUM_OF_HARALICK_FEATURES = 16;
00073 const int NUM_OF_LEVELS = 32;
00074 #else
00075 const int NUM_OF_HARALICK_FEATURES = 0;
00076 const int NUM_OF_LEVELS = 0;
00077 #endif // USE_HARALICK_FEATURES
00078
00080 #ifdef USE_LBP
00081 const int LBP_HISTOGRAM_SIZE = 255;
00082 #else
00083 const int LBP_HISTOGRAM_SIZE = 0;
00084 #endif // USE_LOCAL_MOMENTS
00085
00087 const int NUM_OF_FEATURES = NUM_OF_BASIC_FEATURES + NUM_OF_MOMENTS + NUM_OF_HARALICK_FEATURES + LBP_HISTOGRAM_SIZE;
00088
00090 #if defined(USE_LOCAL_MOMENTS) || defined(USE_HARALICK_FEATURES) || defined(USE_LBP)
00091 const int MIN_NUM_OF_PIXELS = 32;
00092 #else
00093 const int MIN_NUM_OF_PIXELS = 4;
00094 #endif // USE_LOCAL_MOMENTS || USE_HARALICK_FEATURES || USE_LBP
00095
00096 }
00097
00098
00099
00103 class CTriFeatures : public CTriBase, public mds::math::CStaticVector<double, TriFeatures::NUM_OF_FEATURES>
00104 {
00105 public:
00107 typedef double tFeature;
00108
00110 typedef mds::math::CStaticVector<double, TriFeatures::NUM_OF_FEATURES> tVector;
00111
00113 enum { NUM_OF_FEATURES = TriFeatures::NUM_OF_FEATURES };
00114
00116 enum
00117 {
00118 MEAN_VALUE = 0,
00119 VARIANCE,
00120 FIRST_LOCAL_MOMENT = MEAN_VALUE + TriFeatures::NUM_OF_BASIC_FEATURES,
00121 FIRST_HARALICK_FEATURE = FIRST_LOCAL_MOMENT + TriFeatures::NUM_OF_MOMENTS
00122 };
00123
00125 enum
00126 {
00127 ERROR_NOT_EVALUATED = 1,
00128 ERROR_CANNOT_EVALUATE = 2
00129 };
00130
00131 public:
00133 CTriFeatures() : m_iError(ERROR_NOT_EVALUATED), m_iNumOfPixels(0) {}
00134
00136 ~CTriFeatures() {}
00137
00138
00140 tFeature& getFeature(tSize i) { return get(i); }
00141 const tFeature& getFeature(tSize i) const { return get(i); }
00142
00144 void setFeature(tSize i, tFeature Value) { set(i, Value); }
00145
00146
00148 int getNumOfPixels() const { return m_iNumOfPixels; }
00149
00151 void setNumOfPixels(int iValue) { m_iNumOfPixels = iValue; }
00152
00153
00155 bool isError() const { return (m_iError != 0); }
00156
00158 int getError() const { return m_iError; }
00159
00161 void setError(int iError) { m_iError = iError; }
00162
00163
00165 tFeature& getPixelMean() { return get(MEAN_VALUE); }
00166 const tFeature& getPixelMean() const { return get(MEAN_VALUE); }
00167
00169 void setPixelMean(tFeature Value) { set(MEAN_VALUE, Value); }
00170
00171 #ifdef USE_VARIANCE
00172
00173 tFeature& getPixelVariance() { return get(VARIANCE); }
00174 const tFeature& getPixelVariance() const { return get(VARIANCE); }
00175
00177 void setPixelVariance(tFeature Value) { set(VARIANCE, Value); }
00178 #else
00179
00180 tFeature& getPixelVariance() { return m_PixelVariance; }
00181 const tFeature& getPixelVariance() const { return m_PixelVariance; }
00182
00184 void setPixelVariance(tFeature Value) { m_PixelVariance = Value; }
00185 #endif // USE_VARIANCE
00186
00187 #ifdef USE_LOCAL_MOMENTS
00188
00189 tFeature& getLocalMoment(tSize i) { return get(FIRST_LOCAL_MOMENT + i); }
00190 const tFeature& getLocalMoment(tSize i) const { return get(FIRST_LOCAL_MOMENT + i); }
00191
00193 void setLocalMoment(tSize i, tFeature Value) { return set(FIRST_LOCAL_MOMENT + i, Value); }
00194 #endif // USE_LOCAL_MOMENTS
00195
00196 #ifdef USE_HARALICK_FEATURES
00197
00198 tFeature& getHaralickFeature(tSize i) { return get(FIRST_HARALICK_FEATURE + i); }
00199 const tFeature& getHaralickFeature(tSize i) const { return get(FIRST_HARALICK_FEATURE + i); }
00200
00202 void setHaralickFeature(tSize i, tFeature Value) { return set(FIRST_HARALICK_FEATURE + i, Value); }
00203 #endif // USE_HARALICK_FEATURES
00204
00205 protected:
00207 int m_iError;
00208
00210 int m_iNumOfPixels;
00211
00212 #ifndef USE_VARIANCE
00213
00214 tFeature m_PixelVariance;
00215 #endif // USE_VARIANCE
00216 };
00217
00218
00219
00223 class CTriFeaturesExtractor : public CTriBase
00224 {
00225 public:
00227 typedef CTriFeatures::tFeature tFeature;
00228
00230 typedef CTriFeatures tVector;
00231
00232 public:
00234 CTriFeaturesExtractor() { clear(); }
00235
00237 ~CTriFeaturesExtractor() {}
00238
00240 void acumulate(tImage *pImage, vctl::MCTri *pTriangle);
00241
00243 void acumulate(const CTriFeaturesExtractor& Extractor);
00244
00249 bool evaluate(tVector *pVector, bool bCheckNumOfPixels = true);
00250
00252 void clear();
00253
00254 protected:
00256 double m_dSum, m_dSumSqr;
00257
00259 int m_iNumOfPixels;
00260
00261 #ifdef USE_LOCAL_MOMENTS
00262
00263 typedef mds::math::CStaticVector<double, TriFeatures::NUM_OF_MOMENTS> tLocalMoments;
00264
00266 tLocalMoments m_Moments;
00267 #endif // USE_LOCAL_MOMENTS
00268
00269 #ifdef USE_HARALICK_FEATURES
00270
00271 typedef mds::math::CStaticMatrix<int, TriFeatures::NUM_OF_LEVELS, TriFeatures::NUM_OF_LEVELS> tCooMatrix;
00272
00274 tCooMatrix m_Matrix1, m_Matrix2, m_Matrix3, m_Matrix4;
00275 #endif // USE_HARALICK_FEATURES
00276 };
00277
00278
00279
00283 struct STriangleData
00284 {
00286
00287
00289 CTriFeatures m_Features;
00290
00292
00293 STriangleData() {}
00294 };
00295
00296
00297
00298
00299
00300
00301
00304 inline int getTriangleRegion(vctl::MCTri *pTriangle)
00305 {
00306
00307
00308
00309
00310 return (pTriangle) ? pTriangle->GetObject() : -1;
00311 }
00312
00313
00316 inline void setTriangleRegion(vctl::MCTri *pTriangle, int iIndex)
00317 {
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 if( pTriangle )
00329 {
00330 pTriangle->SetObject(iIndex);
00331 }
00332 }
00333
00334
00336 inline CTriFeatures *getTriangleFeatures(vctl::MCTri *pTriangle)
00337 {
00338 STriangleData *pData = (STriangleData *)getTriangleDataPtr(pTriangle);
00339
00340 if( !pData )
00341 {
00342 pData = new STriangleData;
00343 setTriangleDataPtr(pTriangle, pData);
00344 }
00345
00346 return &(pData->m_Features);
00347 }
00348
00349
00350 }
00351 }
00352
00353 #endif // MDS_TRIFEATURES_H
00354