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 VectorXs map_id( const RMatrixXi & ms, const RMatrixXs & s ) {
	eassert( ms.rows() == s.rows() && ms.cols() == s.cols() );
	int Nms = ms.maxCoeff()+1;
	VectorXs r = VectorXs::Zero(Nms);
	for( int j=0; j<s.rows(); j++ )
		for( int i=0; i<s.cols(); i++ )
			r[ ms(j,i) ] = s(j,i);
	return r;
}
Exemple #3
0
static void ImageOverSegmentation_s( MEX_ARGS ) {
    if( nrhs != 1 ) {
        mexErrMsgTxt( "Expected a ImageOverSegmentation" );
        return ;
    }
    if( nlhs != 1 ) {
        mexErrMsgTxt( "Expected a single return argument" );
        return ;
    }
    std::shared_ptr<ImageOverSegmentation> os = mat2Ptr<ImageOverSegmentation>( prhs[0] );
    RMatrixXs s = os->s();
    // Create and write the resulting segmentation
    mwSize dims[2] = {(mwSize)s.rows(), (mwSize)s.cols()};
    plhs[0] = mxCreateNumericArray( 2, dims, mxINT16_CLASS, mxREAL );
    MatrixXs::Map( (short*)mxGetData(plhs[0]), s.rows(), s.cols() ) = s;
}
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;
}