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

MPHistogramHue Class Template Reference

#include <MPHistogramHue.h>

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)
void initialize ()
void load_from_file (std::ifstream &is)
 MPHistogramHue ()
void normalize ()
void print_values (std::ostream &os)
void save_to_file (std::ostream &os)
void update_hist (MPHistogramHue &_cur, MPHistogramHue &_log, float weight=0.5f)
void weighted_add (MPHistogramHue &cur, float weight=0.5f)

Private Member Functions

T * begin ()
const T * end () const
float getHue (const RGBTRIPLE &rgb)
sum ()

Private Attributes

float m_frac
m_hist [N]
m_initialHist [N]
int m_numColors

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


Constructor & Destructor Documentation

MPHistogramHue  )  [inline]
 


Member Function Documentation

void add_uniform weight = 1.0  )  [inline]
 

Definition at line 109 of file MPHistogramHue.h.

References end.

00109                                           {
00110                 const T uniform = weight*(1.0/static_cast<T>(N));
00111                 for (T *it = begin(); it != end(); it++) *it = uniform + *it*(1-weight);
00112         }

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

Definition at line 82 of file MPHistogramHue.h.

00082                                                                          {
00083                 float h;                
00084                 
00085                 h = getHue(rgb);
00086                 m_hist[static_cast<int>(h*m_frac)] += value;
00087         }

T* begin  )  [inline, private]
 

Definition at line 32 of file MPHistogramHue.h.

Referenced by update_hist(), and weighted_add().

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

void clear  )  [inline]
 

Definition at line 96 of file MPHistogramHue.h.

00096                      {
00097                 memset(m_histCur, 0, sizeof(T)*N);
00098         }

void create_initial_hist  )  [inline]
 

Definition at line 151 of file MPHistogramHue.h.

References i.

00151                                    {
00152                 const T uniform = 1.0/static_cast<T>(N);
00153                 for (int i = 0; i < N; i++)
00154                         m_initialHist[i] = uniform;
00155         }

const T* end  )  const [inline, private]
 

Definition at line 36 of file MPHistogramHue.h.

00036                                      {
00037                 return(&(m_hist[N]));
00038         }

T& get_prob const RGBTRIPLE &  rgb  )  [inline]
 

Definition at line 75 of file MPHistogramHue.h.

00075                                                    {
00076                 float h;                
00077                 
00078                 h = getHue(rgb);
00079                 return m_hist[static_cast<int>(h*m_frac)];
00080         }

float getHue const RGBTRIPLE &  rgb  )  [inline, private]
 

Definition at line 46 of file MPHistogramHue.h.

References r.

00046                                                    {
00047                 float   delta,h;
00048                 unsigned char r = rgb.rgbtRed;
00049                 unsigned char g = rgb.rgbtGreen;
00050                 unsigned char b = rgb.rgbtBlue;
00051                 unsigned char cmax = 0, cmin = 0;
00052                 
00053                 if (r >= g) {cmax = r; cmin = g;}
00054                 else {cmax = g; cmin = r;}
00055                 if (b > cmax) cmax = b; 
00056                 else if (b < cmin) cmin = b;
00057                 delta   = static_cast<float>(cmax - cmin);
00058                 if (cmax == r) h = (g-b)/delta;
00059                 else if (cmax == g) h = 2 + (b-r)/delta;
00060                 else h = 4 + (r-g)/delta;       
00061                 h = (h < 0) ? static_cast<float>(h*60.0 + 360.0) : static_cast<float>(h*60.0);
00062                 
00063                 return h;
00064         }

void InitColorModel int  face  )  [inline]
 

Definition at line 184 of file MPHistogramHue.h.

References nonSkinMixGauss::getMixProb(), skinMixGauss::getMixProb(), r, and RGBTRIPLE.

00185         {
00186     int r, g, b;
00187 //              cout << "initializing model face = " << face << endl;
00188     skinMixGauss smg;
00189     nonSkinMixGauss nsmg;
00190     for (r = 0; r < 256; r+=10) {
00191       for (g = 0; g < 256; g+=10) {
00192         for (b = 0; b < 256; b+=10) {           
00193           RGBTRIPLE rgbt;
00194                                         rgbt.rgbtRed = (BYTE)r;
00195                                         rgbt.rgbtGreen = (BYTE)g;
00196                                         rgbt.rgbtBlue = (BYTE)b;
00197                                         double prob;
00198                                         if (face)
00199                 prob = smg.getMixProb(rgbt);
00200                                         else
00201                 prob = nsmg.getMixProb(rgbt);
00202                                         addtobin(rgbt, static_cast<T>(prob));
00203                                 }   
00204       }
00205     }
00206 
00207                 normalize();
00208         }

Here is the call graph for this function:

void initialize  )  [inline]
 

Definition at line 101 of file MPHistogramHue.h.

00101                           {
00102                 memcpy(m_hist, m_initialHist, sizeof(T)*N);
00103 //              clear();
00104 //              add_uniform();
00105 //              normalize();
00106         }

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

Definition at line 141 of file MPHistogramHue.h.

References end.

00141                                               {
00142                 initialize();
00143                 for (T *it = begin(); it != end(); it++) is >> *it;
00144         }

void normalize  )  [inline]
 

Definition at line 89 of file MPHistogramHue.h.

References end.

00089                          {
00090                 T oneoversum = 1.0/sum();
00091                 for (T *it = begin(); it != end(); it++) {
00092                         if (*it) *it *= oneoversum;
00093                 }
00094         }

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

Definition at line 137 of file MPHistogramHue.h.

References end.

00137                                            {
00138                 for (T *it = begin(); it != end(); it++) os << *it << std::endl;
00139         }

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

Definition at line 146 of file MPHistogramHue.h.

00146                                            {
00147                 print_values (os);
00148         }

T sum  )  [inline, private]
 

Definition at line 40 of file MPHistogramHue.h.

References end, and s.

Referenced by update_hist().

00040                 {
00041                 T s = 0.0;
00042                 for (T *it = begin(); it != end(); it++) s += *it;
00043                 return s;
00044         }

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

Definition at line 123 of file MPHistogramHue.h.

References begin(), end, and sum().

00123                                                                                              {
00124                 T *toptr, *fromptr, *logptr;
00125                 T oneoversum = 1.0/_cur.sum();
00126                 fromptr = _cur.begin();
00127                 logptr = _log.begin(); 
00128                 for (toptr = begin(); toptr != end(); fromptr++, toptr++, logptr++) {
00129                         *fromptr *= oneoversum;
00130                         *toptr = static_cast<T>(*fromptr*weight + *toptr*(1-weight));
00131                         *logptr = log(*toptr);
00132                         //cout << "cur = " << *fromptr << ", to = " << *toptr << ", log = " << *logptr << endl;
00133                 }
00134         }

Here is the call graph for this function:

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

Definition at line 115 of file MPHistogramHue.h.

References begin(), and end.

00115                                                                       {
00116                 T *toptr, *fromptr;
00117                 fromptr = cur.begin();
00118                 for (toptr = begin(); toptr != end(); fromptr++, toptr++)
00119                         *toptr = static_cast<T>(*fromptr*weight + *toptr*(1-weight));
00120         }

Here is the call graph for this function:


Member Data Documentation

float m_frac [private]
 

Definition at line 28 of file MPHistogramHue.h.

T m_hist[N] [private]
 

Definition at line 29 of file MPHistogramHue.h.

T m_initialHist[N] [private]
 

Definition at line 30 of file MPHistogramHue.h.

int m_numColors [private]
 

Definition at line 27 of file MPHistogramHue.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