Пример #1
0
static void find_roots( Segmenter *s, FidtrackerX *ft)
{
    int i;

    // we depend on the segmenter initializing certain region fields for us
    // check that here
#ifndef NDEBUG
    sanity_check_region_initial_values( s );
#endif

    // find fiducial roots beginning at leafs

    for( i=0; i < s->region_count; ++i ){
        Region *r = LOOKUP_SEGMENTER_REGION( s, i );

        if( r->adjacent_region_count == 1
                && !(r->flags & (   SATURATED_REGION_FLAG |
                                    FRAGMENTED_REGION_FLAG |
                                    ADJACENT_TO_ROOT_REGION_FLAG |
                                    FREE_REGION_FLAG ) )
                ){

            assert( r->level == NOT_TRAVERSED );
            assert( r->children_visited_count == 0 );
            propagate_descendent_count_and_max_depth_upwards( s, r, ft);
       } 

    }
}
Пример #2
0
void sanity_check_region_initial_values( Segmenter *s )
{
    int i;
    for( i=0; i < s->region_count; ++i ){
        Region *r = LOOKUP_SEGMENTER_REGION( s, i );

        assert( r->level == NOT_TRAVERSED );
        assert( r->children_visited_count == 0 );
        assert( r->descendent_count == 0x7FFF );
    }
}
Пример #3
0
static RegionReference* new_region( Segmenter *s, int x, int y, int colour )
{
    RegionReference *result;
    Region *r;
	int i;

    if( s->freed_regions_head ){
        r = s->freed_regions_head;
        s->freed_regions_head = r->next;
    }else{
        r = LOOKUP_SEGMENTER_REGION( s, s->region_count++ );
    }

	assert( colour == 0 || colour == 255 );

    r->colour = colour;

    r->left = r->right = (short)x;
    r->top = r->bottom = (short)y;

	r->flags = NO_REGION_FLAG;
	r->area = 0;

	r->first_span = NULL;
	r->last_span = NULL;

    r->level = UNKNOWN_REGION_LEVEL;
    r->depth = 0;
    r->children_visited_count = 0;
    r->descendent_count = 0x7FFF;

    r->adjacent_region_count = 0;	
	i = y*(s->width)+x;
	
	r->first_span = LOOKUP_SEGMENTER_SPAN( s,  i );
	r->first_span->start = i;
	r->first_span->end = i;
	r->last_span = r->first_span;
	r->last_span->next = NULL;
	
    result = &s->region_refs[ s->region_ref_count++ ];
    result->redirect = result;
    result->region = r;

    return result;
}
Пример #4
0
int find_regionsX( RegionX *regions, int max_count,
        FidtrackerX *ft, Segmenter *segments, int width, int height)
{

	int i,j=0;
	int max_object_size,min_object_size = 0;
	int pixel = 0;

	max_object_size = height/2; 
	min_object_size = 2;

    initialize_head_region( &ft->root_regions_head );	
	
	for( i=0; i < segments->region_count; ++i ) {
		Region *r = LOOKUP_SEGMENTER_REGION( segments, i );

		if (r->colour == 255) {

				regions[j].left = r->left;
				regions[j].right = r->right;
				regions[j].top = r->top;
				regions[j].bottom = r->bottom;
	
				regions[j].width = r->right-r->left+1;
				regions[j].height = r->bottom-r->top+1;
				regions[j].span = r->first_span;
				regions[j].area = r->area;

				
				if ((regions[j].width>min_object_size) && (regions[j].width<max_object_size) && (regions[j].height>min_object_size) && (regions[j].height<max_object_size)) {
					regions[j].x = regions[j].left+regions[j].width/2;
					regions[j].y = regions[j].top+regions[j].height/2;

					if(ft->pixelwarp) {
						ShortPoint *p;
						pixel = (int)(width * regions[j].y + regions[j].x);
						if ((pixel<0) || (pixel>=width*height)) continue;
						p = &ft->pixelwarp[ pixel ];
						regions[j].x = p->x;
						regions[j].y = p->y;
/*						
						pixel = (int)(width * regions[j].top + regions[j].left);
						if ((pixel<0) || (pixel>=width*height)) continue;
						p = &ft->pixelwarp[ pixel ];
						regions[j].left = p->x;
						regions[j].top = p->y;

						pixel = (int)(width * regions[j].bottom + regions[j].right);
						if ((pixel<0) || (pixel>=width*height)) continue;
						p = &ft->pixelwarp[ pixel ];
						regions[j].right = p->x;
						regions[j].bottom = p->y;
*/
					} 

					j++;
					if (j==max_count) return j;
				}
		} 
	}

	return j;
	
}