BIMAGE * BIMAGE_constructor_char( char *in, /* Input image to copy */ BVECT * dim /* The requested dimensions */ ) { BIMAGE * bimage; int i; int num_pixels; bimage = (BIMAGE *)malloc(sizeof(BIMAGE)); bimage->buf = (float *)malloc(BVECT_prod(dim)*sizeof(float)); num_pixels = BVECT_prod(dim); for (i = 0; i < num_pixels; i++) { bimage->buf[i] = (float)in[i]; } bimage->dim = (BVECT *)malloc(sizeof(BVECT)); bimage->dim->length = dim->length; bimage->dim->buf = (int *)malloc(dim->length*sizeof(int)); memcpy(bimage->dim->buf, dim->buf, dim->length*sizeof(int)); /* Set up the step vector, default to unit steps */ bimage->steps = (float *)malloc(dim->length*sizeof(float)); for (i = 0; i < dim->length; i++) bimage->steps[i] = 1.0; return bimage; }
/* Blank image constructor for BIMAGE 'class' */ BIMAGE * BIMAGE_constructor( BVECT * dim /* The requested dimensions */ ) { BIMAGE * bimage; int i; bimage = (BIMAGE *)malloc(sizeof(BIMAGE)); bimage->buf = (float *)calloc(BVECT_prod(dim), sizeof(float)); bimage->dim = (BVECT *)malloc(sizeof(BVECT)); bimage->dim->length = dim->length; bimage->dim->buf = (int *)malloc(dim->length*sizeof(int)); memcpy(bimage->dim->buf, dim->buf, dim->length*sizeof(int)); /* Set up the step vector, default to unit steps */ bimage->steps = (float *)malloc(dim->length*sizeof(float)); for (i = 0; i < dim->length; i++) bimage->steps[i] = 1.0; return bimage; }
/* lmaxflow A discrete maximum flow algorithm */ int lmaxflow( DBL_TYPE * g, /* The isotropic but non-homogeneous metric */ int * dim_buf, /* The image dimensions */ int dim_length, /* The number of image dimesions */ DBL_TYPE * dbl_type, /* Label image of node types */ DBL_TYPE * out /* The output */ ) { int i, num_pixels; BVECT * dim; int return_val; BIMAGE * g_bimage, * out_bimage; char * type; /* Set up a BVECT to describe the image dimensions, and the source vector */ dim = BVECT_constructor(dim_length); memcpy(dim->buf, dim_buf, dim_length*sizeof(int)); /* Compute the number of pixels for reuse later */ num_pixels = BVECT_prod(dim); /* Allocate a node type array and convert from input type */ type = (char *)malloc(num_pixels * sizeof(char)); for (i = 0; i < num_pixels; i++) { type[i] = (char)dbl_type[i]; } /* Construct the necessary BIMAGEs */ g_bimage = BIMAGE_constructor_double(g, dim); out_bimage = BIMAGE_constructor(dim); /* Compute a maximum flow */ return_val = maxflow( g_bimage, type, out_bimage, ((BIMAGE * *)NULL) ); /* thisa function does not return the mincut, and is only for timings */ /* return_val = maxflowBOOST( g_bimage, type, out_bimage, ((BIMAGE * *)NULL) ); */ /* Copy output buffer across */ for (i = 0; i < num_pixels; i++) { out[i] = (DBL_TYPE)out_bimage->buf[i]; } /* Display any LSTB_error or LSTB_debug messages */ lreadLSTBmsgs(); /* Free everything */ BVECT_destructor(dim); BIMAGE_destructor(g_bimage); BIMAGE_destructor(out_bimage); free((void *)type); return return_val; }