/* * bwdist - build a distance map for a binary stack * * bwdist [-b<int>] infile -o outfile * * -i: inverse the image * -b: byte number for output file (1 (default) or 2) * -sq: build square distance map */ int main(int argc, char *argv[]) { static char *Spec[] = {"<image:string> -o <string>", "[-b<int> | -sq] [-i] [--plane]", NULL}; Process_Arguments(argc, argv, Spec, 1); char *image_file = Get_String_Arg("image"); Stack *stack = Read_Stack(image_file); if (Is_Arg_Matched("-i")) { Stack_Not(stack, stack); } Stack *distmap = NULL; if (!Is_Arg_Matched("-sq")) { distmap = Stack_Bwdist_L(stack, NULL, NULL); Kill_Stack(stack); int kind = GREY; if (Is_Arg_Matched("-b")) { kind = Get_Int_Arg("-b"); } stack = Scale_Float_Stack((float *) distmap->array, distmap->width, distmap->height, distmap->depth, kind); Kill_Stack(distmap); distmap = stack; } else { if (Is_Arg_Matched("--plane")) { distmap = Stack_Bwdist_L_U16P(stack, NULL, 0); Translate_Stack(distmap, GREY, 1); } else { distmap = Stack_Bwdist_L_U16(stack, NULL, 0); } Kill_Stack(stack); } char *out_file = Get_String_Arg("-o"); Write_Stack(out_file, distmap); Kill_Stack(distmap); return 1; }
int main(int argc, char* argv[]) { #if 0 Stack *stack = Read_Stack("../data/binimg.tif"); Set_Matlab_Path("/Applications/MATLAB74/bin/matlab"); Stack *dist = Stack_Bwdist(stack); Stack* seeds = Stack_Local_Max(dist, NULL, STACK_LOCMAX_ALTER1); Stack *out = Scale_Double_Stack((double *) dist->array, stack->width, stack->height, stack->depth, GREY); Translate_Stack(out, COLOR, 1); Rgb_Color color; Set_Color(&color, 255, 0, 0); Stack_Label_Bwc(out, seeds, color); Print_Stack_Info(dist); Write_Stack("../data/test.tif", out); #endif #if 0 Stack *stack = Read_Stack("../data/benchmark/sphere_bw.tif"); //Stack *stack = Read_Stack("../data/sphere_data.tif"); //Stack_Not(stack, stack); int i; /* uint8 *array = stack->array + 512 * 600; for (i = 1; i < 512; i++) { array[i] = 1; } */ //stack->depth = 50; /* long int *label = (long int *) malloc(sizeof(long int) * Stack_Voxel_Number(stack)); */ tic(); Stack *out = Stack_Bwdist_L_U16(stack, NULL, 0); uint16 *out_array = (uint16 *) out->array; printf("%llu\n", toc()); //int *hist = Stack_Hist(out); //Print_Int_Histogram(hist); Stack *out2 = Stack_Bwdist_L(stack, NULL, NULL); float *out2_array = (float *) out2->array; int n = Stack_Voxel_Number(out); int t = 0; int x, y, z; for (i = 0; i < n; i++) { uint16 d2 = (uint16) out2_array[i]; if (out_array[i] != d2){ int area = stack->width * stack->height; STACK_UTIL_COORD(i, stack->width, area, x, y, z); printf("(%d %d %d)", x, y, z); printf("%d %d %d\n", out_array[i], d2, stack->array[i]); t++; } } printf("%d error\n", t); # if 0 //Translate_Stack(out, GREY, 1); float *out_array = (float *) out->array; int i; int n = Stack_Voxel_Number(out); /* for (i = 0; i < n; i++) { out_array[i] = sqrt(out_array[i]); } Stack *out2 = Scale_Float_Stack((float *)out->array, out->width, out->height, out->depth, GREY); */ Stack *out2 = Make_Stack(GREY, out->width, out->height, out->depth); for (i = 0; i < n; i++) { out2->array[i] = (uint8) round(sqrt(out_array[i])); } Write_Stack("../data/test.tif", out2); # endif Write_Stack("../data/test.tif", out); Kill_Stack(out); Kill_Stack(out2); #endif #if 1 Stack *stack = Read_Stack("../data/system/29.tif"); Print_Stack_Info(stack); tic(); Stack *out = Stack_Bwdist_L_U16P(stack, NULL, 0); ptoc(); Stack *golden = Read_Stack("../data/system/29_dist2.tif"); printf("Checking result ...\n"); if (Stack_Identical(out, golden) == FALSE) { printf("Result unmatched.\n"); } else { printf("Good.\n"); } #endif return 0; }