コード例 #1
0
ファイル: drtile.cpp プロジェクト: CVML/lazyflow
vigra::MultiArray<2, coordinate_t>
drtile(const vigra::MultiArrayView<N, weight_t, Stride>& A,
       unsigned long w) {
    #ifdef DEBUG_PRINTING
    std::cout << "drtile(A,w)" << std::endl;
    std::cout << "    A =" << std::endl;
    printArray(A, std::string("    "));
    std::cout << "    A.shape =" << A.shape() << std::endl;
    std::cout << "    w       =" << w << std::endl;
    #endif
    
    std::vector< vigra::TinyVector<coordinate_t, 3> > t;
    vigra::TinyVector<coordinate_t, N> currentCoordinate;
	::detail<N,N,Stride>::drtileImpl(A,w,t, currentCoordinate);
    
    #ifdef DEBUG_PRINTING
    std::cout << "drtile returned:" << std::endl;
    for(unsigned long i=0; i<t.size(); ++i) {
        const coordinate_t& d = t[i][0];
        const coordinate_t& s = t[i][1];
        const coordinate_t& e = t[i][2];
        std::cout << "dimension " << d << ": [" << s << "," << e << ")" << std::endl;
    }
    #endif
    
    typedef vigra::TinyVector<coordinate_t, 2*N> bbox_t;
    typedef vigra::MultiArray<2, coordinate_t> bbox_vector_t;
    
    unsigned long bboxCount = 0;
    for(unsigned long i=0; i<t.size(); ++i) {
        const coordinate_t& d = t[i][0];
        if(d==1) { // || (i < t.size()-1 && d<t[i+1][0])) {
            ++bboxCount;
        }
    }
    
    bbox_vector_t bb(typename bbox_vector_t::size_type(bboxCount, 2*N));
    
    bbox_t b;
    unsigned long j = 0;
    for(unsigned long i=0; i<t.size(); ++i) {
        const coordinate_t& d = t[i][0];
        const coordinate_t& s = t[i][1];
        const coordinate_t& e = t[i][2];
        b[d-1]   = s;
        b[N+d-1] = e;
        if(d==1) { // || (i < t.size()-1 && d<t[i+1][0])) {
            for(unsigned long k=0; k<2*N; ++k) {
                bb(j,k) = b[k];
            }
            ++j;
        }
    }
    return bb;
}
コード例 #2
0
IterativeRegionMerging::IterativeRegionMerging(
		vigra::MultiArrayView<2, int> initialRegions) :
	_grid(initialRegions.shape()),
	_gridEdgeWeights(_grid),
	_ragToGridEdges(_rag),
	_parentNodes(_rag),
	_edgeScores(_rag),
	_mergeTree(initialRegions.shape()*2),
	_mergeEdges(EdgeCompare(_edgeScores)) {

	// get initial region adjecancy graph

	RagType::EdgeMap<std::vector<GridGraphType::Edge> > affiliatedEdges;
	vigra::makeRegionAdjacencyGraph(
			_grid,
			initialRegions,
			_rag,
			affiliatedEdges);

	// get grid edges for each rag edge

	for (RagType::EdgeIt edge(_rag); edge != lemon::INVALID; ++edge)
		_ragToGridEdges[*edge] = affiliatedEdges[*edge];

	// prepare merge-tree image

	_mergeTree = 0;

	// logging

	int numRegions = 0;
	for (RagType::NodeIt node(_rag); node != lemon::INVALID; ++node)
		numRegions++;
	int numRegionEdges = _ragToGridEdges.size();

	LOG_USER(mergetreelog)
			<< "got region adjecancy graph with "
			<< numRegions << " regions and "
			<< numRegionEdges << " edges" << std::endl;
}
コード例 #3
0
ファイル: drtile.cpp プロジェクト: CVML/lazyflow
 static void
 drtileImpl(const vigra::MultiArrayView<M, weight_t, Stride>& A,
            unsigned long w,
            std::vector< vigra::TinyVector<coordinate_t, 3> > & t,
            vigra::TinyVector<coordinate_t, N>& currentShape
           ) {
     #ifdef DEBUG_PRINTING
     std::cout << "detail<"<<N<<","<<M<<">::drtileImpl(A,w="<<w<<") " << std::endl;
     std::cout << "    A =" << std::endl;
     printArray(A, std::string("    "));
     std::cout << "    A.shape =" << A.shape() << std::endl;
     std::cout << "    w       =" << w << std::endl;
     #endif
     
     typedef vigra::TinyVector<coordinate_t, 3> t_t;
     
     //create Abar
     typename if_<M-1==0, vigra::TinyVector<coordinate_t, 1>, vigra::TinyVector<coordinate_t, M-1> >::result Abar_shape;
     if(M-1>=1) {
         for(unsigned long i=0; i<M-1; ++i)
             Abar_shape[i] = A.shape(i);
     }
     else {
         Abar_shape[0] = 1;
     }
     //typename if_<M-1==0, vigra::MultiArray<0, weight_t>, vigra::MultiArray<M-1, weight_t> >::result Abar(Abar_shape);
     vigra::MultiArray<M-1, weight_t> Abar(Abar_shape);
     
     const unsigned long d  = M;
     const unsigned long nd = A.shape(d-1);
     
     coordinate_t prev_k = 0;
     while(prev_k != nd) {
         for(coordinate_t k=prev_k; k<nd+1; ++k) {
             #ifdef DEBUG_PRINTING
             std::cout << "      * prev_k=" << prev_k << ", k=" << k << std::endl;
             #endif
             
             //extend Abar
             if(k<=A.shape(d-1)-1) {
                 if(d-1 == 0) {
                     Abar[0] += A[k];
                 }
                 else {
                     Abar += A.template bind<d-1>(k);
                 }
             }
             
             currentShape[d-1] = k-prev_k;
             
             #ifdef DEBUG_PRINTING
             std::cout << "       * Abar [extend] =" << std::endl;
             printArray(Abar, std::string("        "));
             #endif
             
             //find maximum
             weight_t max = std::numeric_limits<weight_t>::min();
             for(size_t i=0; i<Abar.size(); ++i) {
                 if(Abar[i] > max) {max = Abar[i]; }
             }
             #ifdef DEBUG_PRINTING
             std::cout << "       * max=" << (int)max << std::endl;
             #endif
             
             if(k==nd || max > w) {
                 //unextend Abar
                 if(k<=A.shape(d-1)-1) {
                     if(d-1 == 0) {
                         Abar[0] -= A[k];
                     }
                     else {
                         Abar -= A.template bind<d-1>(k);
                     }
                 }
                 #ifdef DEBUG_PRINTING
                 std::cout << "       * Abar [unextend] =" << std::endl;
                 printArray(Abar, std::string("        "));
                 std::cout << "PUSH: " << d << " " << prev_k << " " << k << std::endl;
                 #endif
                 
                 if(d!=1) {
                     t.push_back(t_t(d, prev_k, k));
                 }
                 else {
                     unsigned long p = 1;
                     for(unsigned long l=0; l<currentShape.size(); ++l) p *= currentShape[l];
                     
                     if (!(p == 1 && Abar[0] ==w)) {
                         t.push_back(t_t(d, prev_k, k));
                     }
                 }
                 
                 if(d>1) {
                     #ifdef DEBUG_PRINTING
                     std::cout << "RECURSE" << std::endl;
                     #endif
                     detail<N,M-1,vigra::StridedArrayTag>::drtileImpl(Abar, w, t, currentShape);
                 }
                 
                 Abar.init(0);
                 prev_k = k;
                 #ifdef DEBUG_PRINTING
                 std::cout << "       * Abar [cleared] =" << std::endl;
                 printArray(Abar, std::string("        "));
                 std::cout << "       * prev_k=" << prev_k << std::endl;
                 #endif
                 break;
             }
         }
     }
 }