/*******************************************************************
 * Function Name: PercentageForegroundinCountour
 * Return Type 	: double
 * Created On	: Apr 23, 2013
 * Created By 	: hrushi
 * Comments		: Calculates the Percentage of foreground pixels that are encompassed inside the foreground contour
 * Arguments	: const CImage& BkImg
 *******************************************************************/
double Contour::PercentageCoverage( const CImage& BkMask) const
{
	double Percentage(0);

	unsigned int DataIndx = 0;
	unsigned int Val = 0;

	unsigned int ForegroundPixels(0), ContourPixels(0);

	for( unsigned int i = 0; i < BkMask.GetNumRows(); i++ )
	{
		for( unsigned int j = 0; j < BkMask.GetNumCols(); j++ )
		{
			DataIndx = i *  BkMask.GetNumCols() + j;

			if(ContourMask.data[ DataIndx ] == MAX_GRAY_VALUE)
			{
				ContourPixels++;
				Val = BkMask.GetGrayVal(i,j);

				if( (int)Val == MAX_GRAY_VALUE )
				{
					ForegroundPixels++;
				}

			}
		}
	}

	Percentage = (double)ForegroundPixels/ContourPixels;

	return Percentage;
}