Using my previous posts Class file and this reference:
http://people.revoledu.com/kardi/tutorial/DecisionTree/how-to-measure-impurity.htm
http://people.revoledu.com/kardi/tutorial/DecisionTree/how-to-measure-impurity.htm
float computeGiniIndex(Mat r, Mat g, Mat b)
{
float giniIndex = 0.0;
float frequency = getFrequencyOfBin(r);
for( int i = 1; i < histSize; i++ )
{
float Hc = abs(getHistogramBinValue(r,i));
giniIndex += Hc*Hc;
}
frequency = getFrequencyOfBin(g);
for( int i = 1; i < histSize; i++ )
{
float Hc = abs(getHistogramBinValue(g,i));
giniIndex += Hc*Hc;
}
frequency = getFrequencyOfBin(b);
for( int i = 1; i < histSize; i++ )
{
float Hc = abs(getHistogramBinValue(b,i));
giniIndex += Hc*Hc;
}
giniIndex = 1 - (giniIndex);
//cout << giniIndex <<endl;
return giniIndex;
}
Comments
Post a Comment