RMatrixXf bin( const RMatrixXs & s, int D, F f ) { const int Ns = s.maxCoeff()+1; RArrayXXf r = RMatrixXf::Zero( Ns, D ); for( int j=0; j<s.rows(); j++ ) for( int i=0; i<s.cols(); i++ ) r.row( s(j,i) ) += f(i,j); return r; }
static VectorXu8 findBoundary( const RMatrixXs & s ) { int Ns = s.maxCoeff()+1; VectorXu8 r = VectorXu8::Zero( Ns ); for( int i=0; i<s.cols(); i++ ) r[ s(0,i) ] = 1; for( int i=0; i<s.cols(); i++ ) r[ s(s.rows()-1,i) ] = 2; for( int i=0; i<s.rows(); i++ ) r[ s(i,0) ] = 3; for( int i=0; i<s.rows(); i++ ) r[ s(i,s.cols()-1) ] = 4; return r; }
static int no( const RMatrixXs & gt ) { return gt.maxCoeff()+1; }