The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPHistogram Class Template Reference

#include <MPHistogram.h>

Inheritance diagram for MPHistogram:

Inheritance graph
[legend]
List of all members.

Public Member Functions

void add_uniform (T weight=1.0)
void addtobin (const RGBTRIPLE &rgb, const T value=1.0)
void clear ()
void create_initial_hist ()
T & get_prob (const RGBTRIPLE &rgb)
void InitColorModel (int face=1)
void initialize ()
void load_from_file (std::ifstream &is)
 MPHistogram ()
void normalize ()
void print_values (std::ostream &os)
void save_to_file (std::ostream &os)
void update_hist (MPHistogram &_cur, MPHistogram &_log, float weight=0.5f)
void weighted_add (MPHistogram &_cur, float weight=0.5f)

Private Member Functions

T * begin ()
const T * end () const
sum ()
int val2bin (const unsigned int &val)

Private Attributes

m_hist [N][N][N]
m_initialHist [N][N][N]
int m_numBins
int m_numColors

template<typename T, unsigned int N>
class MPHistogram< T, N >


Constructor & Destructor Documentation

MPHistogram  )  [inline]
 


Member Function Documentation

void add_uniform weight = 1.0  )  [inline]
 

Definition at line 91 of file MPHistogram.h.

00091                                           {
00092                 const T uniform = weight*(1.0/static_cast<T>(m_numBins));
00093                 for (T *it = begin(); it != end(); it++) *it = uniform + *it*(1-weight);
00094         }

void addtobin const RGBTRIPLE &  rgb,
const T  value = 1.0
[inline]
 

Definition at line 66 of file MPHistogram.h.

Referenced by MPISearchThread::UpdateColorModel().

00066                                                                          {
00067                 m_hist[val2bin(rgb.rgbtRed)][val2bin(rgb.rgbtGreen)][val2bin(rgb.rgbtBlue)] += value;
00068                 //cout << "after added to bin it = " << m_hist[val2bin(rgb.rgbtRed)][val2bin(rgb.rgbtGreen)][val2bin(rgb.rgbtBlue)] << endl;
00069         }

T* begin  )  [inline, private]
 

Definition at line 31 of file MPHistogram.h.

Referenced by MPHistogram< float, NUMBINS >::update_hist(), and MPHistogram< float, NUMBINS >::weighted_add().

00031                            {
00032                 return (&(m_hist[0][0][0]));
00033         }

void clear  )  [inline]
 

Definition at line 78 of file MPHistogram.h.

00078                      {
00079                 memset(m_hist, 0, sizeof(T)*m_numBins);
00080         }

void create_initial_hist  )  [inline]
 

Definition at line 140 of file MPHistogram.h.

00140                                    {
00141                 const T uniform = 1.0/static_cast<T>(m_numBins);
00142                 T *it = &m_initialHist[0][0][0];
00143                 for (int i = 0; i < m_numBins; i++, it++) 
00144                         *it = uniform;
00145         }

const T* end  )  const [inline, private]
 

Definition at line 35 of file MPHistogram.h.

00035                                      {
00036                 return(&(m_hist[N-1][N-1][N-1])+1);
00037         }

T& get_prob const RGBTRIPLE &  rgb  )  [inline]
 

Definition at line 62 of file MPHistogram.h.

Referenced by MPColorTracker::DoSearch(), MPColorTracker::ShowProbs(), and MPISearchThread::UpdateColorModel().

00062                                                    {
00063                 return m_hist[val2bin(rgb.rgbtRed)][val2bin(rgb.rgbtGreen)][val2bin(rgb.rgbtBlue)];
00064         }

void InitColorModel int  face = 1  )  [inline]
 

Definition at line 148 of file MPHistogram.h.

Referenced by MPISearchThread::InitColorModel().

00149         {
00150     int r, g, b;
00151                 int binWidth = (int)(256/N);
00152    
00153 //              cout << "initializing model face = " << face << endl;
00154     skinMixGauss smg;
00155     nonSkinMixGauss nsmg;
00156     for (r = binWidth/2; r < 256; r+=binWidth) {
00157       for (g = binWidth/2; g < 256; g+=binWidth) {
00158         for (b = binWidth/2; b < 256; b+=binWidth) {           
00159           RGBTRIPLE rgbt;
00160                                         rgbt.rgbtRed = (BYTE)r;
00161                                         rgbt.rgbtGreen = (BYTE)g;
00162                                         rgbt.rgbtBlue = (BYTE)b;
00163                                         double prob;
00164                                         if (face)
00165                 prob = smg.getMixProb(rgbt);
00166                                         else
00167                 prob = nsmg.getMixProb(rgbt);
00168                                         addtobin(rgbt, static_cast<T>(prob));
00169                                 } 
00170       }
00171     }
00172 
00173                 normalize();
00174         }

void initialize  )  [inline]
 

Definition at line 83 of file MPHistogram.h.

Referenced by MPISearchThread::UpdateColorModel().

00083                           {
00084                 memcpy(m_hist, m_initialHist, sizeof(T)*m_numBins);
00085 //              clear();
00086 //              add_uniform();
00087 //              normalize();
00088         }

void load_from_file std::ifstream &  is  )  [inline]
 

Definition at line 130 of file MPHistogram.h.

00130                                               {
00131                 initialize();
00132                 for (T *it = begin(); it != end(); it++) is >> *it;
00133         }

void normalize  )  [inline]
 

Definition at line 71 of file MPHistogram.h.

00071                          {
00072                 T oneoversum = 1.0/sum();
00073                 for (T *it = begin(); it != end(); it++) {
00074                         if (*it) *it *= oneoversum;
00075                 }
00076         }

void print_values std::ostream &  os  )  [inline]
 

Definition at line 118 of file MPHistogram.h.

00118                                            {
00119 //              static const float binwidth = static_cast<double>(m_numColors)/static_cast<double>(N);
00120 //              for (int r = 0; r < N; r++) {
00121 //                      for (int g = 0; g < N; g++) {
00122 //                              for (int b = 0; b < N; b++) {
00123 //                                      os << r*binwidth << "\t" << g*binwidth << "\t" << b*binwidth << "\t" << m_hist[r][g][b] << std::endl;
00124 //                              }
00125 //                      }
00126 //              }
00127                 for (T *it = begin(); it != end(); it++) os << *it << std::endl;
00128         }

void save_to_file std::ostream &  os  )  [inline]
 

Definition at line 135 of file MPHistogram.h.

00135                                            {
00136                 print_values (os);
00137         }

T sum  )  [inline, private]
 

Definition at line 46 of file MPHistogram.h.

Referenced by MPHistogram< float, NUMBINS >::update_hist().

00046                 {
00047                 T s = 0.0;
00048                 for (T *it = begin(); it != end(); it++) s += *it;
00049                 return s;
00050         }

void update_hist MPHistogram< T, N > &  _cur,
MPHistogram< T, N > &  _log,
float  weight = 0.5f
[inline]
 

Definition at line 104 of file MPHistogram.h.

Referenced by MPISearchThread::UpdateProbabilities().

00104                                                                                                {
00105                 T *toptr, *fromptr, *logptr;
00106                 T oneoversum = 1.0/_cur.sum();
00107                 fromptr = _cur.begin();
00108                 logptr = _log.begin(); 
00109                 for (toptr = begin(); toptr != end(); fromptr++, toptr++, logptr++) {
00110                         *fromptr *= oneoversum;
00111                         *toptr = static_cast<T>(*fromptr*weight + *toptr*(1-weight));
00112                         *logptr = log(*toptr);
00113                         //cout << "cur = " << *fromptr << ", to = " << *toptr << ", log = " << *logptr << endl;
00114                 }
00115         }

int val2bin const unsigned int &  val  )  [inline, private]
 

Definition at line 39 of file MPHistogram.h.

00039                                                     {
00040 //              static const float alpha = 0.0; /* -0.5 left edge of distribution */
00041                 static const float binwidth = static_cast<double>(m_numColors)/static_cast<double>(N);
00042                 static const float oneoverbinwidth = 1.0/binwidth;
00043                 return(static_cast<int>(static_cast<T>(val)*oneoverbinwidth));
00044         }

void weighted_add MPHistogram< T, N > &  _cur,
float  weight = 0.5f
[inline]
 

Definition at line 97 of file MPHistogram.h.

00097                                                                     {
00098                 T *toptr, *fromptr;
00099                 for (toptr = begin(), fromptr = _cur.begin(); toptr != end(); toptr++, fromptr++)
00100                         *toptr = *fromptr*weight + *toptr*(1-weight);
00101         }


Member Data Documentation

T m_hist[N][N][N] [private]
 

Definition at line 28 of file MPHistogram.h.

T m_initialHist[N][N][N] [private]
 

Definition at line 29 of file MPHistogram.h.

int m_numBins [private]
 

Definition at line 26 of file MPHistogram.h.

int m_numColors [private]
 

Definition at line 27 of file MPHistogram.h.


The documentation for this class was generated from the following file:
Generated on Mon Nov 8 17:08:36 2004 for MPT by  doxygen 1.3.9.1