Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

MatMahalanobis.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Matrix_MatMahalanobis_h
00002 #define Impala_Core_Matrix_MatMahalanobis_h
00003 
00004 #include "Core/Matrix/MatSet.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Matrix
00011 {
00012 
00013 
00016 template<class ArrayT>
00017 inline ArrayT*
00018 MatMahalanobis(ArrayT* a, ArrayT* b, ArrayT* c)
00019 {
00020     typedef typename ArrayT::ArithType ArithT;
00021     typedef typename ArrayT::StorType StorT;
00022 
00023     int nr = MatNrRow(a);
00024     int nc = MatNrCol(b);
00025     ArrayT* m = MatCreate<ArrayT>(nr, nc);
00026     MatSet(m, 0);
00027 
00028     for (int i=0 ; i<nr ; i++)   //for each pixel
00029     {
00030         StorT* miPtr = MatE(m, i, 0);
00031         StorT* aiPtr = MatE(a, i, 0);
00032         for (int j=0 ; j<nc ; j++)   //for each concept
00033         {
00034             double sum = 0;
00035             for (int k=0 ; k<MatNrCol(a) ; k++) //for each filter
00036             {
00037                 double ckj = *MatE(c, k, j);
00038                 double bkj = *MatE(b, k, j);
00039                 if (ckj > 0)  //is this correct?
00040                 {
00041                     sum += ( (aiPtr[k] - bkj) * (aiPtr[k] - bkj) ) / (ckj*ckj);
00042                 }
00043             }   
00044             miPtr[j] = sqrt( sum ); 
00045         }
00046     }
00047     return m;
00048 }
00049 
00050 } // namespace Matrix
00051 } // namespace Core
00052 } // namespace Impala
00053 
00054 #endif

Generated on Fri Mar 19 09:31:15 2010 for ImpalaSrc by  doxygen 1.5.1