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

mixgauss.cpp

Go to the documentation of this file.
00001 /*
00002  *  mixguass.cpp
00003  *  
00004  *
00005  *  Created by Josh Susskind 2004.
00006  *  Copyright (c) 2004 Machine Perception Laboratory
00007  *  University of California San Diego.
00008  *  Please read the disclaimer and notes about redistribution
00009  *  at the end of this file.
00010  *
00011  *  Authors: Josh Susskind
00012  */
00013 #include "mixgauss.h"
00014 #include <string.h>
00015 #include <iostream.h>
00016 #include <math.h>
00017 
00018 static double SKINMEANS[16][3] = {{73.53, 29.94, 17.76},
00019         {249.71, 233.94, 217.49},
00020         {161.68, 116.25, 96.95},
00021         {186.07, 136.62, 114.40},
00022         {189.26, 98.37, 51.18},
00023         {247.00, 152.20, 90.84},
00024         {150.10, 72.66, 37.76},
00025         {206.85, 171.09, 156.34},
00026         {212.78, 152.82, 120.04},
00027         {234.87, 175.43, 138.94},
00028         {151.19, 97.74, 74.59},
00029         {120.52, 77.55, 59.82},
00030         {192.20, 119.62, 82.32},
00031         {214.29, 136.08, 87.24},
00032         {99.57, 54.33, 38.06},
00033         {238.88, 203.08, 176.91}};
00034 
00035 static double SKINCOVARIANCES[16][3] = {{765.40, 121.44, 112.80},
00036         {39.94, 154.44, 396.05}, 
00037         {291.03, 60.48, 162.85}, 
00038         {274.95, 64.60, 198.27},
00039         {633.18, 222.40, 250.69}, 
00040         {65.23, 691.53, 609.92},
00041         {408.63, 200.77, 257.57}, 
00042         {530.08, 155.08, 572.79}, 
00043         {160.57, 84.52, 243.90},
00044         {163.80, 121.57, 279.22},
00045         {425.40, 73.56, 175.11}, 
00046         {330.45, 70.34, 151.82}, 
00047         {152.76, 92.14, 259.15},
00048         {204.90, 140.17, 270.19},
00049         {448.13, 90.18, 151.29}, 
00050         {178.38, 156.27, 404.99}};
00051         
00052 static double SKINWEIGHTS[16] = {0.0294, 
00053         0.0331,
00054         0.0654,
00055         0.0756,
00056         0.0554,
00057         0.0314,
00058         0.0454,
00059         0.0469,
00060         0.0956,
00061         0.0763,
00062         0.1100,
00063         0.0676,
00064         0.0755,
00065         0.0500,
00066         0.0667,
00067         0.0749};
00068 
00069 static double NONSKINMEANS[16][3] = {{254.37, 254.41, 253.82},
00070 {9.39, 8.09, 8.52},
00071 {96.57, 96.95, 91.53},  
00072 {160.44, 162.49, 159.06},       
00073 {74.98, 63.23, 46.33},  
00074 {121.83, 60.88, 18.31}, 
00075 {202.18, 154.88, 91.04},        
00076 {193.06, 201.93, 206.55},       
00077 {51.88, 57.14, 61.55},  
00078 {30.88, 26.84, 25.32},  
00079 {44.97, 85.96, 131.95}, 
00080 {236.02, 236.27, 230.70},       
00081 {207.86, 191.20, 164.12},       
00082 {99.83, 148.11, 188.17},        
00083 {135.06, 131.92, 123.10},       
00084 {135.96, 103.89, 66.88}};
00085 
00086 static double NONSKINCOVARIANCES[16][3] = {{2.77, 2.81, 5.46},  
00087 {46.84, 33.59, 32.48},  
00088 {280.69, 156.79, 436.58},       
00089 {355.98, 115.89, 591.24},       
00090 {414.84, 245.95, 361.27},       
00091 {2502.24, 1383.53, 237.18},
00092 {957.42, 1766.94, 1582.52},
00093 {562.88, 190.23, 447.28},       
00094 {344.11, 191.77, 433.40},       
00095 {222.07, 118.65, 182.41},       
00096 {651.32, 840.52, 963.67},       
00097 {225.03, 117.29, 331.95},       
00098 {494.04, 237.69, 533.52},       
00099 {955.88, 654.95, 916.70},       
00100 {350.35, 130.30, 388.43},       
00101 {806.44, 642.20, 350.36}};
00102 
00103 static double NONSKINWEIGHTS[16] = {0.0637,
00104 0.0516,
00105 0.0864, 
00106 0.0636, 
00107 0.0747,
00108 0.0365, 
00109 0.0349, 
00110 0.0649,
00111 0.0656,
00112 0.1189,
00113 0.0362, 
00114 0.0849,
00115 0.0368,
00116 0.0389, 
00117 0.0943,
00118 0.0477};
00119 
00120 double mixGauss::getMixProb(const int rgb[], double means[][3], double covariances[][3], double weights[]) {
00121         int i, j;
00122         const double PI = 3.14159265358979;
00123         const double constTerm = pow(double(2.0)*PI, double(3.0)/double(2.0));
00124         double sumprobs = 0.0;
00125         for (i = 0; i < 16; i++) {
00126                 double rootDetCov = sqrt(covariances[i][0] * covariances[i][1] * covariances[i][2]);
00127                 double ScalingTerm = double(1.0)/(constTerm*rootDetCov);
00128                 double sum = 0.0;
00129                 for (j = 0; j < 3; j++) {
00130                         sum += pow(rgb[j] - means[i][j], 2) / covariances[i][j];
00131                 }
00132     sumprobs += weights[i] * ScalingTerm * exp(-.5 * sum);
00133         }
00134         return (sumprobs);
00135 }
00136 
00137 skinMixGauss::skinMixGauss () : mixGauss() {
00138         memcpy(m_Means, SKINMEANS, 16*3*sizeof(double));
00139         memcpy(m_Covariances, SKINCOVARIANCES, 16*3*sizeof(double));
00140         memcpy(m_Weights, SKINWEIGHTS, 16*sizeof(double));
00141 }
00142 
00143 skinMixGauss::~skinMixGauss() {}
00144 
00145 double skinMixGauss::getMixProb(const int rgb[]) {
00146         return(mixGauss::getMixProb(rgb, m_Means, m_Covariances, m_Weights));
00147 }
00148 
00149 double skinMixGauss::getMixProb(const RGBTRIPLE rgbt) {
00150         int rgb[3] = {(int)rgbt.rgbtRed, (int)rgbt.rgbtGreen, (int)rgbt.rgbtBlue};
00151         return(mixGauss::getMixProb(rgb, m_Means, m_Covariances, m_Weights));
00152 }
00153 
00154 nonSkinMixGauss::nonSkinMixGauss () : mixGauss() {
00155         memcpy(m_Means, NONSKINMEANS, 16*3*sizeof(double));
00156         memcpy(m_Covariances, NONSKINCOVARIANCES, 16*3*sizeof(double));
00157         memcpy(m_Weights, NONSKINWEIGHTS, 16*sizeof(double));
00158 }
00159 
00160 nonSkinMixGauss::~nonSkinMixGauss(){}
00161 
00162 double nonSkinMixGauss::getMixProb(const int rgb[]) {
00163         return(mixGauss::getMixProb(rgb, m_Means, m_Covariances, m_Weights));
00164 }
00165 
00166 double nonSkinMixGauss::getMixProb(const RGBTRIPLE rgbt) {
00167         int rgb[3] = {(int)rgbt.rgbtRed, (int)rgbt.rgbtGreen, (int)rgbt.rgbtBlue};
00168         return(mixGauss::getMixProb(rgb, m_Means, m_Covariances, m_Weights));
00169 }
00170 
00171 /*
00172  * 
00173  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00174  * 
00175  *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00176  *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00177  *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00178  * 
00179  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00180  * 
00181  */
00182 

Generated on Mon Nov 8 17:07:41 2004 for MPT by  doxygen 1.3.9.1