app/src/main/jni/GroupRunLength.cpp
int GetLineParam( ROWRUNLENGTH *RowRun, int nRun, double &a, double &b )
{
	double	SumX, SumY, SumXY, SumYY;
	int		N;
//Get MMSE approximate of a line
	N = 0;
	SumX = SumY = SumYY = SumXY = 0;
	int i = 0;
	for(; i<nRun; i++ )
	{
		if( RowRun[i].bUsed == FALSE )	continue;
		SumX += (RowRun[i].xs+RowRun[i].xe)*0.5;
		SumY += RowRun[i].y;
		N++;
	}
	if( N<=0 )	return 0;

	double	ax = SumX/N;
	double  ay = SumY/N;

	for( i=0; i<nRun; i++ )
	{
		if( RowRun[i].bUsed == FALSE )	continue;
		SumYY += (RowRun[i].y - ay)*(RowRun[i].y - ay);
		SumXY += (RowRun[i].y - ay)*( 0.5*(RowRun[i].xs + RowRun[i].xe ) - ax);
	}
	b = SumXY / SumYY;
	a = ax - b*ay;
	return 0;
}
/******************************************************************************
/*	Name:		GetLineParam
/*	Function:	Get MMSE estimation of line parameters from the run length 
/*				composing the line. x = b*y + a
/*	Parameter:	RowRun	-- Row (horizontal) run length
/*				nRun	-- Number of run length
/*				a		-- Parameter a
/*				b		-- Parameter b
/*	Return:		0  -- Succeed
/*				-1 -- Error
/*****************************************************************************/
GetLineParam
Function:       Get MMSE estimation of line parameters from the run length
composing the line.
GetLineParam Function : Get MMSE estimation of line parameters from the run length composing the line .
int GetLineParam( ROWRUNLENGTH *RowRun, int nRun, double &a, double &b )
{
	double	SumX, SumY, SumXY, SumYY;
	int		N;
	N = 0;
	SumX = SumY = SumYY = SumXY = 0;
	int i = 0;
	for(; i<nRun; i++ )
	{
		if( RowRun[i].bUsed == FALSE )	continue;
		SumX += (RowRun[i].xs+RowRun[i].xe)*0.5;
		SumY += RowRun[i].y;
		N++;
	}
	if( N<=0 )	return 0;
	double	ax = SumX/N;
	double  ay = SumY/N;
	for( i=0; i<nRun; i++ )
	{
		if( RowRun[i].bUsed == FALSE )	continue;
		SumYY += (RowRun[i].y - ay)*(RowRun[i].y - ay);
		SumXY += (RowRun[i].y - ay)*( 0.5*(RowRun[i].xs + RowRun[i].xe ) - ax);
	}
	b = SumXY / SumYY;
	a = ax - b*ay;
	return 0;
}
int GetLineParam ( ROWRUNLENGTH * RowRun , int nRun , double & a , double & b ) { double SumX , SumY , SumXY , SumYY ; int N ; N = 0 ; SumX = SumY = SumYY = SumXY = 0 ; int i = 0 ; for ( ; i < nRun ; i ++ ) { if ( RowRun [ i ] . bUsed == FALSE ) continue ; SumX += ( RowRun [ i ] . xs + RowRun [ i ] . xe ) * 0.5 ; SumY += RowRun [ i ] . y ; N ++ ; } if ( N <= 0 ) return 0 ; double ax = SumX / N ; double ay = SumY / N ; for ( i = 0 ; i < nRun ; i ++ ) { if ( RowRun [ i ] . bUsed == FALSE ) continue ; SumYY += ( RowRun [ i ] . y - ay ) * ( RowRun [ i ] . y - ay ) ; SumXY += ( RowRun [ i ] . y - ay ) * ( 0.5 * ( RowRun [ i ] . xs + RowRun [ i ] . xe ) - ax ) ; } b = SumXY / SumYY ; a = ax - b * ay ; return 0 ; }
Name:           GetLineParam
Function:       Get MMSE estimation of line parameters from the run length
composing the line.
Name : GetLineParam Function : Get MMSE estimation of line parameters from the run length composing the line .
//Get MMSE approximate of a line