int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s/soma.tif", neuron_name); Stack *stack = Read_Stack(file_path); Stack_Threshold(stack, 1); Stack_Binarize(stack); sprintf(file_path, "../data/%s/mask.tif", neuron_name); Stack *stack2 = Read_Stack(file_path); Stack_Xor(stack, stack2, stack2); sprintf(file_path, "../data/%s/bundle.tif", neuron_name); Write_Stack(file_path, stack2); printf("%s created.\n", file_path); /* Struct_Element *se = Make_Cuboid_Se(3, 3, 3); Stack *stack3 = Stack_Dilate(stack, NULL, se); Stack_And(stack3, stack2, stack2); sprintf(file_path, "../data/%s/objseed.tif", neuron_name); Write_Stack(file_path, stack2); */ return 0; }
int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s/mask.tif", neuron_name); Stack *mask = Read_Stack(file_path); sprintf(file_path, "../data/%s/blobmask.tif", neuron_name); Stack *blobmask = Read_Stack(file_path); int voxel_number = Stack_Voxel_Number(mask); int i; for (i = 0; i < voxel_number; i++) { if (blobmask->array[i] > 0) { mask->array[i] = 3; } } sprintf(file_path, "../data/%s/soma.tif", neuron_name); Write_Stack(file_path, mask); Kill_Stack(mask); Kill_Stack(blobmask); return 0; }
int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s/soma.tif", neuron_name); Stack *stack = Read_Stack(file_path); int i; int n = Stack_Voxel_Number(stack); for (i = 0; i < n; i++) { stack->array[i] = (stack->array[i] == 2); } sprintf(file_path, "../data/%s/arbor.tif", neuron_name); Write_Stack(file_path, stack); Kill_Stack(stack); return 0; }
int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s/blobmask.tif", neuron_name); Stack *stack1 = Read_Stack(file_path); Stack *stack2 = Copy_Stack(stack1); int i; for (i = 0; i < nvoxel; i++) { stack2->array[i] = 3; } sprintf(file_path, "../data/%s/soma.tif", neuron_name); Write_Stack(file_path, stack2); Kill_Stack(stack1); Kill_Stack(stack2); return 0; }
/* * 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[]) { Stack *stack = Read_Stack("../data/lobster_neuron_single.tif"); Stack_Not(stack, stack); Stack *dist = Stack_Bwdist(stack); Stack *seeds = Stack_Local_Max(dist, NULL, STACK_LOCMAX_ALTER1); Write_Stack("../data/lobster_neuron_seed.tif", seeds); Voxel_List *list = Stack_To_Voxel_List(seeds); Pixel_Array *pa = Voxel_List_Sampling(dist, list); Pixel_Array_Write("../data/lobster_neuron_seeds.pa", pa); return 0; }
/** * Find the background of a tif stack. * Output : integer * Input : stack file or bundle file. */ void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { if (nrhs != 1) mexErrMsgTxt("The function takes 1 argument."); if ( !mxIsChar(prhs[0]) ) mexErrMsgTxt("The argument must be a string"); char *filePath = mxArrayToString(prhs[0]); Stack *stack = NULL; if( strlen(filePath)>4 ) { if( Is_Tiff(filePath) ) /* Read file */ stack = Read_Stack(filePath); else if ( Is_Fbdf(filePath) ) { /* Read directory */ File_Bundle fb; initfb(&fb); if( Load_Fbdf(filePath,&fb) ) stack = Read_Stack_Planes(&fb); freefb(&fb); } else mexErrMsgTxt("Unrecongnized file format."); } else { mexErrMsgTxt("Unrecongnized file format."); } if( stack==NULL ) mexErrMsgTxt("Unable to load the stack."); if( stack->kind==GREY || stack->kind==GREY16 ) { int *hist = Stack_Hist(stack); int hist_size = hist[0] + 2; plhs[0] = mxCreateNumericMatrix(hist_size,1,mxINT32_CLASS,mxREAL); int i; int32_t *hist_pointer = (int32_t *) mxGetPr(plhs[0]); for(i = 0; i < hist_size; i++) hist_pointer[i] = hist[i]; free(hist); Kill_Stack(stack); } else { Kill_Stack(stack); mexErrMsgTxt("Unsupported image format."); } }
Stack *load( char *path ) { char *ext = strrchr( path, '.' ); Stack *s; if( strcmp(ext,".tif")==0 || strcmp(ext,".tiff")==0 ) { s = Read_Stack(path); } else if( strcmp(ext,".seq")==0 ) { SeqReader *f = Seq_Open(path); if( !f ) { fprintf(stderr, "Couldn't open file %s", path ); exit(1); } s = Seq_Read_Stack(f); Seq_Close(f); } adjust_scan_bias(s); return s; }
int main(int argc, char *argv[]) { static char *Spec[] = {"<input:string> -o <string> [--dim <string>]", NULL}; Process_Arguments(argc, argv, Spec, 1); if (Is_Arg_Matched("--dim")) { if (strcmp(Get_String_Arg("--dim"), "x") == 0 || strcmp(Get_String_Arg("--dim"), "X") == 0) { Stack *stack = Read_Stack(Get_String_Arg("input")); Image *image = Proj_Stack_Xmax(stack); Write_Image(Get_String_Arg("-o"), image); } } else { Mc_Stack *stack = Read_Mc_Stack(Get_String_Arg("input"), -1); Mc_Stack *proj = Mc_Stack_Mip(stack); Write_Mc_Stack(Get_String_Arg("-o"), proj, NULL); } return 0; }
int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s/mask.tif", neuron_name); Stack *mask = Read_Stack(file_path); sprintf(file_path, "../data/%s/seeds.pa", neuron_name); Pixel_Array *pa = Pixel_Array_Read(file_path); double *pa_array = (double *) pa->array; sprintf(file_path, "../data/%s/seed_offset.ar", neuron_name); int seed_number = pa->size; int *seed_offset = (int *) malloc(sizeof(int) * seed_number); iarray_read(file_path, seed_offset, &seed_number); int max_idx; double max_dist = darray_max(pa_array, pa->size, &max_idx); max_idx = seed_offset[max_idx]; Stack_Label_Object_Dist_N(mask, NULL, max_idx, 1, 2, max_dist * 2.0, 26); Stack_Threshold_Binarize(mask, 1); sprintf(file_path, "../data/%s/blobmask.tif", neuron_name); Write_Stack(file_path, mask); free(seed_offset); Kill_Stack(mask); return 0; }
int main(int argc, char *argv[]) { static char *Spec[] = {"<image:string> -s <int> -o <string>", "[-n <int>]", NULL}; Process_Arguments(argc, argv, Spec, 1); Stack *stack = Read_Stack(Get_String_Arg("image")); int n_nbr = 26; if (Is_Arg_Matched("-n")) { n_nbr = Get_Int_Arg("-n"); } Stack_Label_Large_Objects_N(stack, NULL, 1, 2, Get_Int_Arg("-s") + 1, n_nbr); Stack_Threshold_Binarize(stack, 2); Write_Stack(Get_String_Arg("-o"), stack); return 0; }
int main(int argc, char* argv[]) { #if 0 Mc_Stack *mc_stack = Read_Mc_Stack("../data/benchmark/L3_12bit.lsm", -1); Stack *stack = Mc_Stack_To_Stack(mc_stack, COLOR, NULL); Write_Stack_U("../data/test.lsm", stack, "../data/benchmark/L3_12bit.lsm"); #endif #if 0 //Print_Lsm_Info("/Users/zhaot/Data/stitching_12bit/70208_2BcPhR_R1_GR1_B1_L001.lsm"); Mc_Stack *stack = Read_Mc_Stack("../data/benchmark/L3_12bit.lsm", -1); Print_Mc_Stack_Info(stack); Mc_Stack_Grey16_To_8(stack, 1); Write_Mc_Stack("../data/test.lsm", stack, "../data/benchmark/L3_12bit.lsm"); #endif #if 0 Read_Stack("/Users/zhaot/Data/slice15overlay/L05.tif"); #endif #if 0 /* char *filePath = "test"; if( strlen(filePath)>4 ) if( strcmp(filePath+strlen(filePath)-4,".tif")==0 || strcmp(filePath+strlen(filePath)-4,".TIF")==0 ) printf("%d\n", 1); printf("%d\n", 0); */ Is_Tiff("test"); //Write_Stack("/Users/zhaot/Work/neurolabi/data/test.tif", Read_Stack("/Users/zhaot/Data/slice15overlay/L03.tif")); Write_Stack("../data/test.tif", Read_Stack("../data/L05.tif")); #endif #if 0 Stack *stack = Read_Stack("../data/fly_neuron.tif"); Write_Stack("../data/test2.tif", stack); #endif #if 0 int big_endian; Tiff_Reader *tif = Open_Tiff_Reader("/Users/zhaot/Data/Stacks for stitching/Set 1 65C07/GL_100708_R1_GR1_B1_L013.lsm", &big_endian, 1); Tiff_Writer *tif2 = Open_Tiff_Writer("../data/test.tif", 0); Tiff_IFD *ifd = NULL; int depth = 0; while ((ifd = Read_Tiff_IFD(tif)) != NULL) { if (Convert_LSM_2_RGB(ifd, 0, 0) != NULL) { Write_Tiff_IFD(tif2, ifd); depth++; } Free_Tiff_IFD(ifd); } printf("%d\n", depth); //Kill_Tiff_IFD(ifd); Kill_Tiff_Reader(tif); Close_Tiff_Writer(tif2); Stack *stack = Read_Stack("../data/test.tif"); Write_Stack("../data/test.tif", stack); #endif #if 0 Tiff_Reader *reader; reader = Open_Tiff_Reader("../data/test.lsm",NULL,1); Tiff_IFD *ifd = Read_Tiff_IFD(reader); Print_Tiff_IFD(ifd, stdout); Kill_Tiff_Reader(reader); #endif #if 0 Stack *stack = Read_Lsm_Stack("/Users/zhaot/Data/stitch/Set 3 17F12/GL_100208_R1_GR1_B1_L07.lsm", -1); //Stack *stack = Read_Lsm_Stack("/Users/zhaot/Data/nathan/2p internal[497-545,565-649nm] 40x 2x12us 900nm 5pct cleared 1.lsm", 0); Tiff_IFD *ifd; { Tiff_Reader *reader; reader = Open_Tiff_Reader("/Users/zhaot/Data/stitch/Set 3 17F12/GL_100208_R1_GR1_B1_L08.lsm",NULL,1); while (lsm_thumbnail_flag(ifd = Read_Tiff_IFD(reader)) != 0) { //Advance_Tiff_Reader(reader); if (End_Of_Tiff(reader)) { ifd = NULL; TZ_ERROR(ERROR_IO_READ); break; } } } //Write_Stack("../data/test.tif", stack); Print_Tiff_IFD(ifd, stdout); if (stack != NULL) { Write_Lsm_Stack("../data/test.lsm", stack, ifd); } stack = Read_Lsm_Stack("../data/test.lsm", -1); Write_Stack("../data/test.tif", stack); #endif #if 0 Mc_Stack *mc_stack = Read_Mc_Stack("../data/test.tif", 1); Print_Mc_Stack_Info(mc_stack); Write_Mc_Stack("../data/test2.tif", mc_stack, NULL); Free_Mc_Stack(mc_stack); mc_stack = Read_Mc_Stack("../data/test2.tif", -1); Print_Mc_Stack_Info(mc_stack); printf("%d\n", Mc_Stack_Usage()); #endif #if 0 Stack *stack = Read_Lsm_Stack("../data/test.lsm", -1); Print_Stack_Info(stack); Write_Stack("../data/test.tif", stack); #endif #if 0 Fix_Lsm_File("../data/test/result1.lsm"); Print_Lsm_Info("../data/test/result1.lsm"); #endif #if 0 Stack *stack = Make_Stack(1, 5, 5, 5); int nvoxel = Stack_Voxel_Number(stack); int i; for (i = 0; i < nvoxel; i++) { stack->array[i] = i; } Write_Stack("../data/test.tif", stack); stack = Read_Stack("../data/test.tif"); Write_Stack("../data/test2.tif", stack); #endif #if 0 Stack *stack = Read_Stack(fullpath("../data/fly_neuron_n11/", "mask2.tif", NULL)); Print_Stack_Info(stack); #endif #if 0 //Print_Lsm_Info("/Users/zhaot/Data/stitch/Set 3 17F12/GL_100208_R1_GR1_B1_L07.lsm"); //FILE *fp = fopen("/Users/zhaot/Data/stitch/set1/GL_100708_R1_GR1_B1_L015.lsm", "r"); FILE *fp = fopen("../data/test.lsm", "r"); char endian[3]; endian[2] = '\0'; fread(endian, 1, 2, fp); printf("Endian: %s\n", endian); uint16_t magic; fread(&magic, 2, 1, fp); printf("Magic number: %u\n", magic); uint32_t ifd_offset; fread(&ifd_offset, 4, 1, fp); printf("1st IFD offset: %u\n", ifd_offset); fseek(fp, ifd_offset, SEEK_SET); uint16_t nifd; fread(&nifd, 2, 1, fp); printf("Number of IFD: %u\n", nifd); uint16_t ifd_label; fread(&ifd_label, 2, 1, fp); uint16_t i; for (i = 1; i < nifd; i++) { if (ifd_label == TIF_CZ_LSMINFO) { break; } fseek(fp, 10, SEEK_CUR); fread(&ifd_label, 2, 1, fp); } printf("IFD label: %u\n", ifd_label); uint16_t ifd_type; fread(&ifd_type, 2, 1, fp); printf("IFD type: %u\n", ifd_type); uint32_t ifd_length; fread(&ifd_length, 4, 1, fp); printf("IFD length: %u\n", ifd_length); fread(&ifd_offset, 4, 1, fp); printf("Lsm info offset: %u\n", ifd_offset); /* fseek(fp, ifd_offset + CZ_LSMINFO_DIMZ_OFFSET, SEEK_SET); int32_t dimz = 80; fwrite(&dimz, 4, 1, fp); printf("Number of slices: %d\n", dimz); */ int offset = 88; fseek(fp, ifd_offset, SEEK_SET); /* uint32_t value = 0; fwrite(&value, 4, 1, fp); fseek(fp, ifd_offset + offset, SEEK_SET); */ /* Fprint_File_Binary(fp, 24, stdout); fclose(fp); return 1; */ Cz_Lsminfo lsminfo; fread(&lsminfo, sizeof(Cz_Lsminfo), 1, fp); printf("%lu\n", sizeof(Cz_Lsminfo)); if (lsminfo.u32MagicNumber == 67127628) { printf("Version 1.5, 1.6 and 2.0\n"); } else if (lsminfo.u32MagicNumber == 50350412) { printf("Version 1.3\n"); } else { printf("Unknown version\n"); return 1; } printf("Structure size: %d\n", lsminfo.s32StructureSize); printf("Stack size: %d x %d x %d\n", lsminfo.s32DimensionX, lsminfo.s32DimensionY, lsminfo.s32DimensionZ); printf("Number of channels: %d\n", lsminfo.s32DimensionChannels); switch (lsminfo.s32DataType) { case 1: printf("8-bit unsigned integer.\n"); break; case 2: printf("12-bit unsigned integer.\n"); break; case 5: printf("32-bit float.\n"); break; case 0: printf("Different channels have different types.\n"); break; } printf("Thumbnail size: %d x %d\n", lsminfo.s32ThumbnailX, lsminfo.s32ThumbnailY); printf("Voxel size: %g x %g x %g um\n", lsminfo.f64VoxelSizeX * 1000000, lsminfo.f64VoxelSizeY * 1000000, lsminfo.f64VoxelSizeZ * 1000000); printf("Scan type: "); switch (lsminfo.u16ScanType) { case 0: printf("normal x-y-z-scan\n"); break; case 1: printf("Z-Scan\n"); break; case 2: printf("Line Scan\n"); break; case 3: printf("Time series x-y\n"); break; case 4: printf("Time series x-z\n"); break; case 5: printf("Time series - Mean of ROIS\n"); break; } if (lsminfo.u32OffsetVectorOverlay == 0) { printf("There is no vector overlay\n"); } else { printf("Vector overlay found\n"); } if (lsminfo.u32OffsetInputLut == 0) { printf("There is no input LUT\n"); } else { printf("Input LUT found\n"); } if (lsminfo.u32OffsetOutputLut == 0) { printf("There is no color palette\n"); } else { printf("Color palette found\n"); } if (lsminfo.u32OffsetChannelColors == 0) { printf("There is no channel color or channel name\n"); } else { printf("Channel colors and channel names fournd\n"); } if (lsminfo.f64TimeInterval == 0) { printf("There is no time interval\n"); } else { printf("Time interval: %lg sec\n", lsminfo.f64TimeInterval); } if (lsminfo.u32OffsetScanInformation == 0) { printf("There is no information about devide settings\n"); } else { printf("Scan information found. Offset: %u\n", lsminfo.u32OffsetScanInformation); /* Lsm_Scan_Info *info = (Lsm_Scan_Info*) (data + lsminfo.u32OffsetScanInformation + 20); printf("Information type: %u\n", info->u32Entry); printf("Data type: %u\n", info->u32Type); printf("Data size: %u\n", info->u32Size); */ /* uint8_t *byte = (uint8_t*) (data + lsminfo.u32OffsetScanInformation); printf("%u\n", byte[8]); */ } if (lsminfo.u32OffsetKsData == 0) { printf("There is no Zeiss Vision KS-3d data\n"); } else { printf("Zeiss Vision KS-3d data found. Offset: %u\n", lsminfo.u32OffsetKsData); } if (lsminfo.u32OffsetRoi == 0) { printf("There is no ROI\n"); } else { printf("ROI found\n"); } if (lsminfo.u32OffsetNextRecording == 0) { printf("There is no second image\n"); } else { printf("Second image found\n"); } fclose(fp); #endif #if 0 FILE *fp = fopen("/Users/zhaot/Data/stitch/set1/GL_100708_R1_GR1_B1_L014.lsm", "r+"); char endian[3]; endian[2] = '\0'; fread(endian, 1, 2, fp); printf("Endian: %s\n", endian); fpos_t pos; fgetpos(fp, &pos); printf("%d\n", pos); fseek(fp, 0, SEEK_SET); uint32_t x = 254; printf("%lu bytes written\n", fwrite(&x, sizeof(uint32_t), 1, fp)); fgetpos(fp, &pos); printf("%d\n", pos); Fprint_File_Binary(fp, 8, stdout); fclose(fp); #endif #if 0 Stack *stack = Read_Lsm_Stack("../data/GL_100208_R1_GR1_B1_L07.lsm", -1); Write_Stack_U("../data/test.lsm", stack, "../data/GL_100208_R1_GR1_B1_L07.lsm"); #endif #if 0 //Stack *stack = Read_Lsm_Stack("/Users/zhaot/Data/neurolineage/lsm/Twin-Spot_Gal4-GH146_nc_11-2.lsm", 0); Stack *stack = Read_Stack_U("../data/test2.tif"); Write_Stack_U("../data/test.tif", stack, NULL); #endif #if 0 Stack *stack = Read_Stack("../data/mouse_single_org/traced.tif"); Write_Stack("../data/test.tif", stack); #endif #if 0 /* test writing large stack */ Mc_Stack *stack = Make_Mc_Stack(GREY, 1024, 1024, 1024, 3); size_t n = (size_t) 1024 * 1024 * 1024 * 3; size_t i; for (i = 0; i < n; i++) { stack->array[i] = i % 255; } Write_Mc_Stack("../data/test.tif", stack, NULL); #endif #if 0 /* test reading large stack */ Mc_Stack *stack = Read_Mc_Stack("../data/test.tif", -1); Print_Mc_Stack_Info(stack); #endif #if 0 /* test writing a raw stack */ Mc_Stack *stack = Read_Mc_Stack("/Users/zhaot/Data/SynapseSpotted2_S124-3_1to59NF1Crop1_enhanced_Sample.tif", -1); //Print_Stack_Info(stack); Write_Mc_Stack("../data/test.raw", stack, NULL); #endif #if 0 /* test reading a raw stack */ /* Stack *stack = Read_Raw_Stack("/Users/zhaot/Data/jinny/slice15_overplaped.raw"); Print_Stack_Info(stack); Write_Stack("../data/test.tif", stack); */ Stack *stack = Read_Sc_Stack("/Users/zhaot/Data/jinny/proofread_slice15_3to11/detectedresults/slice15_3to11_crop01_detected_test.raw", 1); Print_Stack_Info(stack); Write_Stack("../data/test.tif", stack); #endif #if 0 Stack *stack = Read_Sc_Stack("/Users/zhaot/Data/jinny/drawMask/slice15_3to33_4_30_result.raw", 2); stack = Read_Stack_U("/Users/zhaot/Data/jinny/drawMask/slice15_3to33.raw"); #endif #if 0 Stack *stack = Read_Stack_U("/Users/zhaot/Work/neurolabi/data/diadem_d1_095.xml"); Print_Stack_Info(stack); #endif #if 0 Stack *stack = Read_Stack_U("/Users/zhaot/Work/neurolabi/data/diadem_d1_001.xml"); Print_Stack_Info(stack); Mc_Stack *mc_stack = Mc_Stack_Rewrap_Stack(stack); printf("%d\n", Stack_Usage()); printf("%d\n", Mc_Stack_Usage()); Print_Mc_Stack_Info(mc_stack); Write_Mc_Stack("../data/test.tif", mc_stack, NULL); Free_Mc_Stack(mc_stack); mc_stack = Read_Mc_Stack("/Users/zhaot/Work/neurolabi/data/diadem_d1_001.xml", -1); printf("%d\n", Mc_Stack_Usage()); #endif #if 0 int size[3]; Stack_Size_F("../data/benchmark/L3_12bit.lsm", size); iarray_print2(size, 3, 1); #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("/Users/zhaot/Data/Julie/All_tiled_nsyb5_Sum.lsm", -1); Print_Mc_Stack_Info(stack); Write_Mc_Stack("../data/test.lsm", stack, "/Users/zhaot/Data/Julie/All_tiled_nsyb5_Sum.lsm"); #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("../data/test.lsm", -1); Print_Mc_Stack_Info(stack); #endif #if 0 Mc_Stack *stack = NULL; stack = Read_Mc_Stack("/Users/zhaot/Data/colorsep/16D01.1-14.lsm", 0); Write_Mc_Stack("/Users/zhaot/Data/colorsep/channel1.tif", stack, NULL); stack = Read_Mc_Stack("/Users/zhaot/Data/colorsep/16D01.1-14.lsm", 1); Write_Mc_Stack("/Users/zhaot/Data/colorsep/channel2.tif", stack, NULL); stack = Read_Mc_Stack("/Users/zhaot/Data/colorsep/16D01.1-14.lsm", 2); Write_Mc_Stack("/Users/zhaot/Data/colorsep/channel3.tif", stack, NULL); stack = Read_Mc_Stack("/Users/zhaot/Data/colorsep/16D01.1-14.lsm", 3); Write_Mc_Stack("/Users/zhaot/Data/colorsep/channel4.tif", stack, NULL); /* Write_Mc_Stack("../data/test.lsm", stack, "/Users/zhaot/Data/Julie/All_tiled_nsyb5_Sum.lsm"); */ #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("/Users/zhaot/Data/colorsep/16D01.1-14.lsm", -1); Print_Mc_Stack_Info(stack); Stack grey_stack = Mc_Stack_Channel(stack, 3); grey_stack.text = "\0"; Write_Stack("../data/test.tif", &grey_stack); #endif #if 0 printf("Channel number: %d\n", Lsm_Channel_Number("../data/12bit/70208_2BcPhR_R1_GR1_B1_L003.lsm")); printf("Image type:"); switch (Lsm_Pixel_Type("../data/12bit/70208_2BcPhR_R1_GR1_B1_L003.lsm")) { case GREY8: printf(" uint8\n"); break; case GREY16: printf(" uint16\n"); break; case FLOAT32: printf(" float32\n"); break; default: printf(" unknown\n"); } #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("../data/brainbow/CA3.lsm", 0); Print_Mc_Stack_Info(stack); Write_Mc_Stack("../data/test.tif", stack, NULL); #endif #if 0 Stack *stack = Read_Stack_U("../data/test.xml"); Write_Stack("../data/test.tif", stack); #endif #if 0 int width, height, depth, kind; Tiff_Attribute("../data/stack8.tif", 0, &kind, &width, &height, &depth); printf("%d %d %d %d\n", width, height, depth, kind); #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("../data/neuronsep/Lee_Lab/13C01_BLM00090_D2.v3dpdb", 1); Print_Mc_Stack_Info(stack); Write_Mc_Stack("../data/test.tif", stack, NULL); #endif #if 0 //Mc_Stack *stack = Read_Mc_Stack("../data/benchmark/bfork_2d.tif", -1); //Mc_Stack *stack = Read_Mc_Stack("../data/neuronsep/Lee_Lab/13C01_BLM00090_D2.v3dpdb", 0); Mc_Stack *stack = Read_Mc_Stack("../data/neuronsep/stitched-1.v3dpdb", 0); //stack->depth = 1; Stack ch = Mc_Stack_Channel(stack, 0); printf("%g\n", Stack_Sum(&ch)); int *hist = Stack_Hist(&ch); Print_Int_Histogram(hist); Print_Mc_Stack_Info(stack); Write_Mc_Stack("../data/test.tif", stack, NULL); #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("../data/neurosep/aljosha/stitched-1858872924438528098.v3draw", -1); Print_Mc_Stack_Info(stack); #endif #if 1 IMatrix *mat = IMatrix_Read("../data/test/session2/body_map/body_map00161.imat"); printf("%d: %d x %d x %d\n", (int) mat->ndim, mat->dim[0], mat->dim[1], mat->dim[2]); Stack *stack = Make_Stack(GREY, mat->dim[0], mat->dim[1], mat->dim[2]); size_t nvoxel = Stack_Voxel_Number(stack); for (size_t i = 0; i < nvoxel; ++i) { stack->array[i] = (mat->array[i]) >> 24; } Write_Stack("../data/test.tif", stack); #endif return 0; }
int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s.tif", neuron_name); Stack *stack = Read_Stack(file_path); int nvoxel = Stack_Voxel_Number(stack); /* 1.5GB for double */ if (nvoxel < iround(962592768.0 / (8.0 + stack->kind))) { DMatrix *filter = Mexihat_2D_D(2.0, NULL); filter->ndim = 3; filter->dim[2] = 1; DMatrix *out = Filter_Stack_Fast_D(stack, filter, NULL, 0); Kill_Stack(stack); Kill_DMatrix(filter); stack = Scale_Double_Stack(out->array, out->dim[0], out->dim[1], out->dim[2], GREY); Kill_DMatrix(out); } else { printf("Large volume data. Float version activated.\n"); FMatrix *filter = Mexihat_2D_F(2.0, NULL); filter->ndim = 3; filter->dim[2] = 1; FMatrix *out = Filter_Stack_Fast_F(stack, filter, NULL, 0); Kill_Stack(stack); Kill_FMatrix(filter); stack = Scale_Float_Stack(out->array, out->dim[0], out->dim[1], out->dim[2], GREY); Kill_FMatrix(out); } sprintf(file_path, "../data/%s/highpass.tif", neuron_name); Write_Stack(file_path, stack); printf("%s created.\n", file_path); Kill_Stack(stack); /* DMatrix_Negative(out); stack = Scale_Double_Stack(out->array, out->dim[0], out->dim[1], out->dim[2], GREY16); */ //Stack_View sv = Stack_View_DMatrix(out); /* Stack *locmax = Stack_Local_Max(stack, NULL, STACK_LOCMAX_NONFLAT); sprintf(file_path, "../data/%s/highpass_locmin.tif", neuron_name); Write_Stack(file_path, locmax); printf("%s created.\n", file_path); Kill_Stack(locmax); */ return 0; }
int main() { #if 0 char *filepath = "../data/fly_neuron_n2/graph_d.swc"; Neuron_Structure *ns = Neuron_Structure_From_Swc_File(filepath); Neuron_Component_Arraylist *comp_array = Neuron_Structure_Branch_Point(ns); filepath = "../data/fly_neuron_n2.tif"; Stack *stack = Read_Stack(filepath); Translate_Stack(stack, COLOR, 1); int i; Stack_Draw_Workspace *ws = New_Stack_Draw_Workspace(); for (i = 0; i < comp_array->length; i++) { Neuron_Component_Draw_Stack(comp_array->array + i, stack, ws); } Kill_Stack_Draw_Workspace(ws); Write_Stack("../data/test.tif", stack); #endif #if 0 Stack *stack = NULL; Locseg_Chain *chain1 = Read_Locseg_Chain("../data/fly_neuron_n3/chain0.tb"); Locseg_Chain *chain2 = Read_Locseg_Chain("../data/fly_neuron_n3/chain10.tb"); Connection_Test_Workspace *ws = New_Connection_Test_Workspace(); Connection_Test_Workspace_Read_Resolution(ws, "../data/fly_neuron_n1.res"); Neurocomp_Conn conn; conn.mode = NEUROCOMP_CONN_HL; Locseg_Chain_Connection_Test(chain1, chain2, stack, 1.0, &conn, ws); Print_Neurocomp_Conn(&conn); #endif #if 0 Locseg_Chain **chain = (Locseg_Chain**) malloc(sizeof(Locseg_Chain*) * 3); chain[0] = Read_Locseg_Chain("../data/mouse_single_org/chain4.tb"); chain[1] = Read_Locseg_Chain("../data/mouse_single_org/chain19.tb"); chain[2] = Read_Locseg_Chain("../data/mouse_single_org/chain64.tb"); Stack *signal = Read_Stack("../data/mouse_single_org.tif"); Connection_Test_Workspace *ctw = New_Connection_Test_Workspace(); FILE *fp = fopen("../data/mouse_single_org.res", "r"); darray_fscanf(fp, ctw->resolution, 3); Neuron_Component *chain_array = Make_Neuron_Component_Array(3); int i; for (i = 0; i < 3; i++) { Set_Neuron_Component(chain_array + i, NEUROCOMP_TYPE_LOCSEG_CHAIN, chain[i]); } Neuron_Structure *ns = Locseg_Chain_Comp_Neurostruct(chain_array, 3, signal, 1.0, ctw); Graph *graph = ns->graph; Process_Neuron_Structure(ns); Print_Neuron_Structure(ns); Neuron_Structure_Crossover_Test(ns, 0.5375); printf("\ncross over changed: \n"); Print_Neuron_Structure(ns); #endif #if 0 Neuron_Structure *ns = Make_Neuron_Structure(5); Set_Neuron_Component(ns->comp, NEUROCOMP_TYPE_GEO3D_CIRCLE, New_Geo3d_Circle()); Set_Neuron_Component(ns->comp + 1, NEUROCOMP_TYPE_GEO3D_CIRCLE, New_Geo3d_Circle()); Set_Neuron_Component(ns->comp + 2, NEUROCOMP_TYPE_GEO3D_CIRCLE, New_Geo3d_Circle()); Set_Neuron_Component(ns->comp + 3, NEUROCOMP_TYPE_GEO3D_CIRCLE, New_Geo3d_Circle()); Set_Neuron_Component(ns->comp + 4, NEUROCOMP_TYPE_GEO3D_CIRCLE, New_Geo3d_Circle()); NEUROCOMP_GEO3D_CIRCLE(ns->comp)->radius = 1.5; NEUROCOMP_GEO3D_CIRCLE(ns->comp + 1)->radius = 2.5; NEUROCOMP_GEO3D_CIRCLE(ns->comp + 2)->radius = 3.5; NEUROCOMP_GEO3D_CIRCLE(ns->comp + 3)->radius = 4.5; NEUROCOMP_GEO3D_CIRCLE(ns->comp + 4)->radius = 5.5; ns->graph = Make_Graph(5, 4, 0); //Graph_Add_Edge(ns->graph, 0, 1); Graph_Add_Edge(ns->graph, 1, 3); Graph_Add_Edge(ns->graph, 1, 4); Graph_Add_Edge(ns->graph, 0, 2); Graph_Set_Directed(ns->graph, TRUE); Print_Graph(ns->graph); Swc_Tree *tree = Neuron_Structure_To_Swc_Tree_Circle_Z(ns, 1.0, NULL); Print_Swc_Tree(tree); Swc_Tree_To_Dot_File(tree, "../data/test2.dot"); #endif #if 0 int n; Neuron_Component *chain_array = Dir_Locseg_Chain_Nc("../data/fly_neuron_n22", "^chain.*\\.tb", &n, NULL); Neuron_Structure *ns = Locseg_Chain_Comp_Neurostruct(chain_array, n, NULL, 1.0, NULL); Process_Neuron_Structure(ns); Neuron_Structure* ns2= Neuron_Structure_Locseg_Chain_To_Circle(ns); Neuron_Structure_To_Tree(ns2); Graph_To_Dot_File(ns2->graph, "../data/test.dot"); Swc_Tree *tree = Neuron_Structure_To_Swc_Tree_Circle_Z(ns2, 1.0, NULL); Swc_Tree_Remove_Zigzag(tree); //Swc_Tree_Tune_Fork(tree); //Print_Swc_Tree(tree); Write_Swc_Tree("../data/test.swc", tree); #endif #if 0 Graph *graph = Neuron_Structure_Import_Xml_Graph("../data/mouse_single_org/trueconn2.xml"); Graph_Normalize_Edge(graph); Graph_Remove_Duplicated_Edge(graph); Graph *graph2 = Neuron_Structure_Import_Xml_Graph("../data/mouse_single_org/conn.xml"); Graph_Normalize_Edge(graph2); Graph_Remove_Duplicated_Edge(graph2); Graph_Workspace *gw = New_Graph_Workspace(); int n = Graph_Edge_Count(graph, graph2->edges, graph2->nedge, gw); printf("fp: %d\n", graph2->nedge - n); printf("tp: %d\n", n); printf("fn: %d\n", graph->nedge - n); double p = (double) n / graph2->nedge; double r = (double) n / graph->nedge; printf("precision: %g\n", p); printf("recall: %g\n", r); printf("F-measure: %g\n", 2.0 * (p * r) / (p + r)); #endif #if 0 Neuron_Structure *ns = Make_Neuron_Structure(2); Local_Neuroseg *locseg = New_Local_Neuroseg(); Locseg_Chain *chain1 = New_Locseg_Chain(); Locseg_Chain_Add(chain1, locseg, NULL, DL_TAIL); Set_Neuron_Component(ns->comp, NEUROCOMP_TYPE_LOCSEG_CHAIN, chain1); Locseg_Chain *chain2 = New_Locseg_Chain(); locseg = New_Local_Neuroseg(); double bottom[3] = {10, 10, 5}; double top[3] = {5, 5, 5}; Local_Neuroseg_Set_Bottom_Top(locseg, bottom, top); Locseg_Chain_Add(chain2, locseg, NULL, DL_TAIL); Set_Neuron_Component(ns->comp + 1, NEUROCOMP_TYPE_LOCSEG_CHAIN, chain2); Neurocomp_Conn *conn = New_Neurocomp_Conn(); Connection_Test_Workspace *ctw = New_Connection_Test_Workspace(); Locseg_Chain_Connection_Test(chain2, chain1, NULL, 1.0, conn, ctw); Neuron_Structure_Add_Conn(ns, 1, 0, conn); Print_Neuron_Structure(ns); Neuron_Structure *ns2 = Neuron_Structure_Locseg_Chain_To_Circle_S(ns, 1.0, 1.0); Neuron_Structure_To_Swc_File(ns2, "../data/test.swc"); #endif #if 0 int n; Locseg_Chain **chain_array = Dir_Locseg_Chain_Nd("../data/diadem_a1_part3", "^chain.*\\.tb", &n, NULL); /* Locseg_Chain **chain_array = Locseg_Chain_Import_List("../data/diadem_a1_part2/good_tube.txt", &n); */ //n = 100; /* Locseg_Chain **chain_array = (Locseg_Chain**) malloc(sizeof(Locseg_Chain*) * 2); n = 2; chain_array[0] = Read_Locseg_Chain("../data/diadem_a1_part2/chain58.tb"); chain_array[1] = Read_Locseg_Chain("../data/diadem_a1_part2/chain154.tb"); */ Stack *stack = Read_Stack("../data/diadem_a1_part3.tif"); Stack *mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(mask); Sp_Grow_Workspace *sgw = New_Sp_Grow_Workspace(); sgw->size = Stack_Voxel_Number(stack); sgw->resolution[0] = 0.0375 * 2.0; sgw->resolution[1] = 0.0375 * 2.0; sgw->resolution[2] = 0.33; Sp_Grow_Workspace_Set_Mask(sgw, mask->array); sgw->wf = Stack_Voxel_Weight_S; Stack_Sp_Grow_Infer_Parameter(sgw, stack); Neuron_Structure *ns = Locseg_Chain_Sp_Grow_Reconstruct(chain_array, n, stack, 1.0, sgw); Print_Neuron_Structure(ns); Graph_To_Dot_File(ns->graph, "../data/test.dot"); //Neuron_Structure_To_Swc_File(ns, "../data/test.swc"); Neuron_Structure *ns2 = Neuron_Structure_Locseg_Chain_To_Circle_S(ns, 1.0, 1.0); //double root[3] = {31, 430, 0}; double root[3] = {1221, 449, 8.5}; Swc_Tree *tree = Neuron_Structure_To_Swc_Tree_Circle_Z(ns2, 1.0, root); Swc_Tree_Clean_Root(tree); Swc_Tree_Resort_Id(tree); Write_Swc_Tree("../data/test.swc", tree); #endif #if 0 int n; Locseg_Chain **chain_array = Dir_Locseg_Chain_Nd("../data/diadem_e1", "^chain.*\\.tb", &n, NULL); //n = 100; /* Locseg_Chain **chain_array = (Locseg_Chain**) malloc(sizeof(Locseg_Chain*) * 2); n = 2; chain_array[0] = Read_Locseg_Chain("../data/diadem_a1_part2/chain58.tb"); chain_array[1] = Read_Locseg_Chain("../data/diadem_a1_part2/chain154.tb"); */ Stack *stack = Read_Stack("../data/diadem_e1.tif"); Stack *mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(mask); Sp_Grow_Workspace *sgw = New_Sp_Grow_Workspace(); sgw->size = Stack_Voxel_Number(stack); sgw->resolution[0] = 0.3296485; sgw->resolution[1] = 0.3296485; sgw->resolution[2] = 1.0; Sp_Grow_Workspace_Set_Mask(sgw, mask->array); sgw->wf = Stack_Voxel_Weight_S; Stack_Sp_Grow_Infer_Parameter(sgw, stack); Neuron_Structure *ns = Locseg_Chain_Sp_Grow_Reconstruct(chain_array, n, stack, 1.0, sgw); Print_Neuron_Structure(ns); //Neuron_Structure_To_Swc_File(ns, "../data/test.swc"); Neuron_Structure *ns2 = Neuron_Structure_Locseg_Chain_To_Circle_S(ns, 1.0, 1.0); Graph_To_Dot_File(ns2->graph, "../data/test.dot"); double root[3] = {31, 430, 0}; //double root[3] = {4882, 1797, 19}; Swc_Tree *tree = Neuron_Structure_To_Swc_Tree_Circle_Z(ns2, 1.0, root); //Swc_Tree_Clean_Root(tree); Swc_Tree_Resort_Id(tree); Write_Swc_Tree("../data/test2.swc", tree); #endif #if 0 int n; Locseg_Chain **chain_array = Dir_Locseg_Chain_Nd("../data/benchmark/stack_graph/fork", "^chain.*\\.tb", &n, NULL); Stack *stack = Read_Stack("../data/benchmark/stack_graph/fork/fork.tif"); Stack *mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(mask); Sp_Grow_Workspace *sgw = New_Sp_Grow_Workspace(); sgw->size = Stack_Voxel_Number(stack); Sp_Grow_Workspace_Set_Mask(sgw, mask->array); sgw->wf = Stack_Voxel_Weight_S; Stack_Sp_Grow_Infer_Parameter(sgw, stack); Neuron_Structure *ns = Locseg_Chain_Sp_Grow_Reconstruct(chain_array, n, stack, 1.0, sgw); Neuron_Structure *ns2 = Neuron_Structure_Locseg_Chain_To_Circle_S(ns, 1.0, 1.0); Swc_Tree *tree = Neuron_Structure_To_Swc_Tree_Circle_Z(ns2, 1.0, NULL); //Swc_Tree_Clean_Root(tree); Swc_Tree_Resort_Id(tree); Write_Swc_Tree("../data/test.swc", tree); #endif #if 0 int n = 3; Locseg_Chain **chain_array = (Locseg_Chain**) malloc(sizeof(Locseg_Chain) * n); chain_array[0] = Read_Locseg_Chain("/Users/zhaot/Work/neurolabi/data/benchmark/stack_graph/fork/chain0.tb"); chain_array[1] = Read_Locseg_Chain("/Users/zhaot/Work/neurolabi/data/benchmark/stack_graph/fork/chain1.tb"); chain_array[2] = New_Locseg_Chain(); printf("%d\n", Locseg_Chain_Is_Empty(chain_array[2])); Stack *stack = Read_Stack("../data/benchmark/stack_graph/fork/fork.tif"); Stack *mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(mask); Sp_Grow_Workspace *sgw = New_Sp_Grow_Workspace(); sgw->size = Stack_Voxel_Number(stack); Sp_Grow_Workspace_Set_Mask(sgw, mask->array); sgw->wf = Stack_Voxel_Weight_S; Stack_Sp_Grow_Infer_Parameter(sgw, stack); Neuron_Structure *ns = Locseg_Chain_Sp_Grow_Reconstruct(chain_array, n, stack, 1.0, sgw); Neuron_Structure *ns2 = Neuron_Structure_Locseg_Chain_To_Circle_S(ns, 1.0, 1.0); Swc_Tree *tree = Neuron_Structure_To_Swc_Tree_Circle_Z(ns2, 1.0, NULL); //Swc_Tree_Clean_Root(tree); Swc_Tree_Remove_Zigzag(tree); Swc_Tree_Resort_Id(tree); Write_Swc_Tree("../data/test2.swc", tree); #endif #if 0 Neuron_Structure *ns = New_Neuron_Structure(); ns->graph = New_Graph(); Graph_Add_Edge(ns->graph, 0, 1); Graph_Add_Edge(ns->graph, 0, 2); Graph_Add_Edge(ns->graph, 2, 3); Graph_Add_Edge(ns->graph, 2, 4); Graph_Add_Edge(ns->graph, 4, 5); Graph_Add_Edge(ns->graph, 5, 6); ns->conn = (Neurocomp_Conn*) malloc(sizeof(Neurocomp_Conn) * ns->graph->nedge); ns->conn[0].info[0] = 0; ns->conn[0].info[1] = 0; ns->conn[0].cost = 0.0; ns->conn[0].mode = NEUROCOMP_CONN_LINK; ns->conn[1].info[0] = 1; ns->conn[1].info[1] = 1; ns->conn[1].cost = 0.0; ns->conn[1].mode = NEUROCOMP_CONN_LINK; ns->conn[2].info[0] = 0; ns->conn[2].info[1] = 0; ns->conn[2].cost = 0.0; ns->conn[2].mode = NEUROCOMP_CONN_LINK; ns->conn[3].info[0] = 1; ns->conn[3].info[1] = 0; ns->conn[3].cost = 1.0; ns->conn[3].mode = NEUROCOMP_CONN_HL; ns->conn[4].info[0] = 0; ns->conn[4].info[1] = 1; ns->conn[4].cost = 0.0; ns->conn[4].mode = NEUROCOMP_CONN_LINK; ns->conn[5].info[0] = 1; ns->conn[5].info[1] = 1; ns->conn[5].cost = 1.0; ns->conn[5].mode = NEUROCOMP_CONN_LINK; Neuron_Structure_Merge_Locseg_Chain(ns); #endif #if 0 Neuron_Structure *ns = New_Neuron_Structure(); ns->graph = New_Graph(); ns->comp = Dir_Locseg_Chain_Nc("../data/diadem_e3", "^chain.*\\.tb", &(ns->graph->nvertex), NULL); Graph_Add_Edge(ns->graph, 0, 1); Graph_Add_Edge(ns->graph, 0, 2); Graph_Add_Edge(ns->graph, 2, 3); Graph_Add_Edge(ns->graph, 3, 4); Graph_Add_Edge(ns->graph, 4, 5); ns->conn = (Neurocomp_Conn*) malloc(sizeof(Neurocomp_Conn) * ns->graph->nedge); ns->conn[0].info[0] = 0; ns->conn[0].info[1] = 0; ns->conn[0].cost = 0.0; ns->conn[0].mode = NEUROCOMP_CONN_LINK; ns->conn[1].info[0] = 0; ns->conn[1].info[1] = 0; ns->conn[1].cost = 0.0; ns->conn[1].mode = NEUROCOMP_CONN_LINK; ns->conn[2].info[0] = 0; ns->conn[2].info[1] = 0; ns->conn[2].cost = 1.0; ns->conn[2].mode = NEUROCOMP_CONN_LINK; ns->conn[3].info[0] = 0; ns->conn[3].info[1] = 0; ns->conn[3].cost = 2.0; ns->conn[3].mode = NEUROCOMP_CONN_LINK; ns->conn[4].info[0] = 0; ns->conn[4].info[1] = 0; ns->conn[4].cost = 0.0; ns->conn[4].mode = NEUROCOMP_CONN_LINK; int i; for (i = 0; i < ns->graph->nvertex; i++) { printf("%d ", Locseg_Chain_Length(NEUROCOMP_LOCSEG_CHAIN(ns->comp+i))); } printf("\n"); Neuron_Structure_Merge_Locseg_Chain(ns); for (i = 0; i < ns->graph->nvertex; i++) { printf("%d ", Locseg_Chain_Length(NEUROCOMP_LOCSEG_CHAIN(ns->comp+i))); } printf("\n"); #endif #if 0 int n; Locseg_Chain **chain_array = Dir_Locseg_Chain_Nd("../data/diadem_e1", "^chain.*\\.tb", &n, NULL); Stack *stack = Read_Stack("../data/diadem_e1.tif"); Stack *mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(mask); Sp_Grow_Workspace *sgw = New_Sp_Grow_Workspace(); sgw->size = Stack_Voxel_Number(stack); sgw->resolution[0] = 0.3296485; sgw->resolution[1] = 0.3296485; sgw->resolution[2] = 1.0; Sp_Grow_Workspace_Set_Mask(sgw, mask->array); sgw->wf = Stack_Voxel_Weight_S; Stack_Sp_Grow_Infer_Parameter(sgw, stack); Neuron_Structure *ns = Locseg_Chain_Sp_Grow_Reconstruct(chain_array, n, stack, 1.0, sgw); Neuron_Structure_Merge_Locseg_Chain(ns); int i; char filepath[100]; for (i = 0; i < ns->graph->nvertex; i++) { Locseg_Chain_Regularize(NEUROCOMP_LOCSEG_CHAIN(ns->comp+i)); if (Locseg_Chain_Is_Empty(NEUROCOMP_LOCSEG_CHAIN(ns->comp+i)) == FALSE) { sprintf(filepath, "../data/tmp/chain%d.tb", i); Write_Locseg_Chain(filepath, NEUROCOMP_LOCSEG_CHAIN(ns->comp+i)); } } #endif #if 0 Stack *stack = Read_Stack("../data/benchmark/fork2/fork2.tif"); Neuron_Structure *ns = New_Neuron_Structure(); ns->graph = New_Graph(); ns->comp = Dir_Locseg_Chain_Nc("../data/benchmark/fork2/tubes", "^chain.*\\.tb", &(ns->graph->nvertex), NULL); coordinate_3d_t roots[3]; roots[0][0] = 51; roots[0][1] = 23; roots[0][2] = 60; roots[1][0] = 51; roots[1][1] = 23; roots[1][2] = 40; roots[2][0] = 25; roots[2][1] = 76; roots[2][2] = 60; Neuron_Structure_Break_Root(ns, roots, 3); Neuron_Structure_Load_Root(ns, roots, 3); Connection_Test_Workspace *ctw = New_Connection_Test_Workspace(); ctw->dist_thre = 100.0; ctw->sp_test = FALSE; Locseg_Chain_Comp_Neurostruct_W(ns, stack, 1.0, ctw); Process_Neuron_Structure(ns); Neuron_Structure_To_Tree(ns); /* Neuron_Structure_Remove_Conn(ns, 0, 2); Neuron_Structure_Remove_Conn(ns, 2, 0); */ Neuron_Structure_Remove_Negative_Conn(ns); Neuron_Structure* ns2= NULL; ns2 = Neuron_Structure_Locseg_Chain_To_Circle_S(ns, 1.0, 1.0); Neuron_Structure_To_Tree(ns2); Swc_Tree *tree = Neuron_Structure_To_Swc_Tree_Circle_Z(ns2, 1.0, NULL); Swc_Tree_Resort_Id(tree); Write_Swc_Tree("../data/test3.swc", tree); #endif #if 1 Stack *stack = NULL; Locseg_Chain *chain1 = Read_Locseg_Chain("../data/benchmark/diadem/diadem_e1/chain22.tb"); Locseg_Chain *chain2 = Read_Locseg_Chain("../data/benchmark/diadem/diadem_e1/chain0.tb"); Connection_Test_Workspace *ws = New_Connection_Test_Workspace(); Connection_Test_Workspace_Read_Resolution(ws, "../data/diadem_e3.res"); Neurocomp_Conn conn; conn.mode = NEUROCOMP_CONN_HL; Locseg_Chain_Connection_Test(chain1, chain2, stack, 1.0, &conn, ws); Print_Neurocomp_Conn(&conn); #endif return 0; }
int main(int argc, char *argv[]) { static char *Spec[] = {"[-z <double>]", NULL}; Process_Arguments(argc, argv, Spec, 1); #if 0 Locseg_Chain *chain1 = Read_Locseg_Chain("../data/ct017/test5/chain2.bn"); Locseg_Chain *chain2 = Read_Locseg_Chain("../data/ct017/test5/chain1.bn"); if (Is_Arg_Matched("-z")) { double z_scale = Get_Double_Arg("-z"); Locseg_Chain_Scale_Z(chain1, z_scale); Locseg_Chain_Scale_Z(chain2, z_scale); } Neurocomp_Conn conn; Locseg_Chain_Connection_Test_P(chain1, chain2, &conn); Print_Neurocomp_Conn(&conn); double scale = 2.0; double offset = 5.0; Local_Neuroseg *locseg1; if (conn.info[0] == 0) { locseg1 = Locseg_Chain_Head_Seg(chain1); Local_Neuroseg_Stretch(locseg1, scale, offset, -1); } else { locseg1 = Locseg_Chain_Tail_Seg(chain1); Local_Neuroseg_Stretch(locseg1, scale, offset, 1); } Local_Neuroseg *locseg2 = Locseg_Chain_Peek_Seg_At(chain2, conn.info[1]); Local_Neuroseg_Stretch(locseg2, scale, offset, 0); printf("%g\n", Local_Neuroseg_Planar_Dist_L(locseg1, locseg2)); FILE *fp = fopen("../data/ct017/test5/test.swc", "w"); /* to avoid v3d bug */ Local_Neuroseg *tmp_locseg = Copy_Local_Neuroseg(locseg1); tmp_locseg->seg.r1 = 0.1; Local_Neuroseg_Swc_Fprint(fp, tmp_locseg, 0, -1); Local_Neuroseg_Swc_Fprint(fp, locseg1, 2, -1); Local_Neuroseg_Swc_Fprint(fp, locseg2, 4, -1); fclose(fp); Locseg_Chain_Connection_Test(chain1, chain2, NULL, 1.0, &conn, NULL); Print_Neurocomp_Conn(&conn); #endif #if 0 double z_scale = 0.5375; Locseg_Chain *chain[11]; char file_path[100]; int i, j; for (i = 0; i < 11; i++) { sprintf(file_path, "../data/mouse_single_org/chain%d.bn", i); chain[i] = Read_Locseg_Chain(file_path); Locseg_Chain_Scale_Z(chain[i], z_scale); } Neurocomp_Conn conn; for (i = 0; i < 11; i++) { for (j = 0; j < 11; j++) { if (i != j) { if (Locseg_Chain_Connection_Test_P(chain[i], chain[j], &conn) < 5.0) { printf("%d -> %d \n", i, j); Print_Neurocomp_Conn(&conn); } } } } #endif #if 0 double z_scale = 0.5375; int n = 278; Locseg_Chain *chain[n]; char file_path[100]; int i, j; for (i = 0; i < n; i++) { sprintf(file_path, "../data/mouse_single_org/chain%d.bn", i); chain[i] = Read_Locseg_Chain(file_path); Locseg_Chain_Scale_Z(chain[i], z_scale); } Locseg_Chain *hook = chain[19]; Neurocomp_Conn conn; for (i = 0; i < n; i++) { if (i != 19) { if (Locseg_Chain_Connection_Test_P(hook, chain[i], &conn) < 5.0) { printf("19 -> %d \n", i); Print_Neurocomp_Conn(&conn); } } } #endif #if 0 double z_scale = 0.32; Locseg_Chain *chain[17]; char file_path[100]; int i, j; for (i = 0; i < 17; i++) { sprintf(file_path, "../data/fly_neuron_n1/chain%d.bn", i); chain[i] = Read_Locseg_Chain(file_path); Locseg_Chain_Scale_Z(chain[i], z_scale); } Neurocomp_Conn conn; for (i = 0; i < 17; i++) { for (j = 0; j < 17; j++) { if (i != j) { if (Locseg_Chain_Connection_Test_P(chain[i], chain[j], &conn) < 5.0) { printf("%d -> %d \n", i, j); Print_Neurocomp_Conn(&conn); } } } } #endif #if 0 double z_scale = 0.1400; //double z_scale = 1.0; int n = 12; Locseg_Chain *chain[n]; char file_path[100]; int i, j; for (i = 0; i < n; i++) { sprintf(file_path, "../data/ct017/test6/chain%d.bn", i); chain[i] = Read_Locseg_Chain(file_path); Locseg_Chain_Scale_Z(chain[i], z_scale); } Neurocomp_Conn conn; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i != j) { if (Locseg_Chain_Connection_Test_P(chain[i], chain[j], &conn) < 10.0) { printf("%d -> %d \n", i, j); Print_Neurocomp_Conn(&conn); } } } } #endif #if 0 //double z_scale = 0.1400; double z_scale = 1.20; int n = 5; Locseg_Chain *chain[n]; char file_path[100]; int i, j; for (i = 0; i < n; i++) { sprintf(file_path, "../data/ct017/test7/chain%d.bn", i); chain[i] = Read_Locseg_Chain(file_path); Locseg_Chain_Scale_Z(chain[i], z_scale); } Neurocomp_Conn conn; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i != j) { if (Locseg_Chain_Connection_Test_P(chain[i], chain[j], &conn) < 10.0) { printf("%d -> %d \n", i, j); Print_Neurocomp_Conn(&conn); } } } } #endif #if 0 double z_scale = 1.20; //double z_scale = 1.0; Stack *stack = Read_Stack("../data/lobster_neuron_org.tif"); int n = 5; Locseg_Chain *chain[n]; char file_path[100]; int i, j; for (i = 0; i < n; i++) { sprintf(file_path, "../data/ct017/test7/chain%d.bn", i); chain[i] = Read_Locseg_Chain(file_path); //Locseg_Chain_Scale_Z(chain[i], z_scale); } Connection_Test_Workspace *ctw = New_Connection_Test_Workspace(); ctw->z_scale = z_scale; Neurocomp_Conn conn; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i != j) { if (Locseg_Chain_Connection_Test(chain[i], chain[j], stack, 1.0, &conn, ctw)) { printf("%d -> %d \n", i, j); Print_Neurocomp_Conn(&conn); } } } } #endif #if 0 Locseg_Chain *chain = Read_Locseg_Chain("../data/ct017/test6/chain7.bn"); Local_Neuroseg *locseg = Locseg_Chain_Tail_Seg(chain); Print_Local_Neuroseg(locseg); Stack *stack = Read_Stack("../data/mouse_neuron_sp2.tif"); double *profile = Local_Neuroseg_Height_Profile(locseg, stack, 1.0, 11, STACK_FIT_CORRCOEF, NULL); darray_write("../data/profile1.bn", profile, 11); #endif #if 0 Locseg_Chain *chain = Read_Locseg_Chain("../data/ct017/test6/chain7.bn"); Local_Neuroseg *locseg = Locseg_Chain_Tail_Seg(chain); Print_Local_Neuroseg(locseg); Stack *stack = Read_Stack("../data/mouse_neuron_sp2.tif"); int n; double record[11]; Locseg_Chain *chain2 = Local_Neuroseg_Push(locseg, stack, 1.0, STACK_FIT_OUTER_SIGNAL, record, &n); Print_Locseg_Chain(chain2); Write_Locseg_Chain("../data/test.tb", chain2); return 1; Locseg_Chain *chain3 = Read_Locseg_Chain("../data/ct017/test6/chain6.bn"); Locseg_Chain_Scale_Z(chain2, 0.14); Locseg_Chain_Scale_Z(chain3, 0.14); Neurocomp_Conn conn; Locseg_Chain_Connection_Test(chain2, chain3, NULL, 1.0, &conn, NULL); Print_Neurocomp_Conn(&conn); #endif #if 0 Locseg_Chain *chain = Read_Locseg_Chain("../data/ct017/test6/chain9.bn"); Local_Neuroseg *locseg = Locseg_Chain_Tail_Seg(chain); //Local_Neuroseg *locseg = Locseg_Chain_Head_Seg(chain); //Flip_Local_Neuroseg(locseg); Print_Local_Neuroseg(locseg); Stack *stack = Read_Stack("../data/mouse_neuron_sp2.tif"); int n; double record[11]; Locseg_Chain *chain2 = Local_Neuroseg_Push(locseg, stack, 1.0, STACK_FIT_OUTER_SIGNAL, record, &n); Print_Locseg_Chain(chain2); Write_Locseg_Chain("../data/test.bn", chain2); return 1; Locseg_Chain *chain3 = Read_Locseg_Chain("../data/ct017/test6/chain9.bn"); Locseg_Chain_Scale_Z(chain2, 0.14); Locseg_Chain_Scale_Z(chain3, 0.14); Neurocomp_Conn conn; Locseg_Chain_Connection_Test(chain3, chain2, stack, 1.0, &conn, NULL); Print_Neurocomp_Conn(&conn); #endif #if 0 double z_scale = 0.1400; //double z_scale = 1.0; Stack *stack = Read_Stack("../data/mouse_neuron_sp2.tif"); int n = 12; Locseg_Chain *chain[n]; char file_path[100]; int i, j; for (i = 0; i < n; i++) { sprintf(file_path, "../data/ct017/test6/chain%d.bn", i); chain[i] = Read_Locseg_Chain(file_path); //Locseg_Chain_Scale_Z(chain[i], z_scale); } Connection_Test_Workspace *ctw = New_Connection_Test_Workspace(); ctw->z_scale = 0.14; Neurocomp_Conn conn; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i != j) { if (Locseg_Chain_Connection_Test(chain[i], chain[j], stack, 1.0, &conn, ctw)) { printf("%d -> %d \n", i, j); Print_Neurocomp_Conn(&conn); } } } } #endif #if 0 //double z_scale = 0.32; //double z_scale = 1.0; Stack *stack = Read_Stack("../data/fly_neuron_n1.tif"); int n = 17; Locseg_Chain *chain[n]; char file_path[100]; int i, j; for (i = 0; i < n; i++) { sprintf(file_path, "../data/fly_neuron_n1/chain%d.tb", i); chain[i] = Read_Locseg_Chain(file_path); //Locseg_Chain_Scale_Z(chain[i], z_scale); } Connection_Test_Workspace *ctw = New_Connection_Test_Workspace(); ctw->resolution[0] = 0.32; ctw->resolution[1] = 0.32; ctw->resolution[2] = 1.0; Neurocomp_Conn conn; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i != j) { if (Locseg_Chain_Connection_Test(chain[i], chain[j], stack, 1.0, &conn, ctw)) { printf("%d -> %d \n", i, j); Print_Neurocomp_Conn(&conn); } } } } #endif #if 0 Locseg_Chain *chain = Read_Locseg_Chain("../data/fly_neuron_n1/chain3.bn"); Local_Neuroseg *locseg = Locseg_Chain_Tail_Seg(chain); //Flip_Local_Neuroseg(locseg); Print_Local_Neuroseg(locseg); Stack *stack = Read_Stack("../data/fly_neuron_n1.tif"); int n; double record[11]; Locseg_Chain *chain2 = Local_Neuroseg_Push(locseg, stack, 1.0, STACK_FIT_CORRCOEF, record, &n); Print_Locseg_Chain(chain2); Write_Locseg_Chain("../data/test.bn", chain2); return 1; Locseg_Chain *chain3 = Read_Locseg_Chain("../data/fly_neuron_n1/chain0.bn"); Locseg_Chain_Scale_Z(chain2, 0.32); Locseg_Chain_Scale_Z(chain3, 0.32); Neurocomp_Conn conn; Locseg_Chain_Connection_Test(chain2, chain3, stack, 1.0, &conn, NULL); Print_Neurocomp_Conn(&conn); #endif return 0; }
int main(int argc, char *argv[]) { static char *Spec[] = {"<input:string> -o <string>", "[-count <int>] [-dist <int>] [-minobj <int>]", NULL}; Process_Arguments(argc, argv, Spec, 1); Stack *input = Read_Stack(Get_String_Arg("input")); int nregion = Stack_Max(input, NULL); int nvoxel = Stack_Voxel_Number(input); int i; Stack *stack = Make_Stack(GREY, Stack_Width(input), Stack_Height(input), Stack_Depth(input)); Stack *out = Make_Stack(GREY, Stack_Width(input), Stack_Height(input), Stack_Depth(input)); Zero_Stack(out); int nobj = 0; for (i = 1; i <= nregion; i++) { int j; int count = 0; for (j = 0; j < nvoxel; j++) { stack->array[j] = (input->array[j] == i); } Stack *out3 = NULL; int maxcount = 100000; if (Is_Arg_Matched("-count")) { maxcount = Get_Int_Arg("-count"); } if (count > maxcount) { out3 = Copy_Stack(stack); Stack_Addc_M(out3, nobj); nobj++; } else { Stack *distmap = Stack_Bwdist_L_U16P(stack, NULL, 0); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->mask = Copy_Stack(distmap); int mindist = 10; if (Is_Arg_Matched("-dist")) { mindist = Get_Int_Arg("-dist"); } Stack_Threshold_Binarize(ws->mask, mindist); Translate_Stack(ws->mask, GREY, 1); int minobj = 100; if (Is_Arg_Matched("-minobj")) { minobj = Get_Int_Arg("-minobj"); } Object_3d_List *objs = Stack_Find_Object(ws->mask, 1, minobj); Zero_Stack(ws->mask); Stack_Draw_Objects_Bw(ws->mask, objs, -255); ws->min_level = 1; ws->start_level = 65535; out3 = Stack_Watershed(distmap, ws); Stack_Addc_M(out3, nobj); nobj += Object_3d_List_Length(objs); Kill_Stack(distmap); Kill_Stack_Watershed_Workspace(ws); Kill_Object_3d_List(objs); } Stack_Add(out, out3, out); Kill_Stack(out3); } printf("number of regions: %d\n", nobj); Write_Stack(Get_String_Arg("-o"), out); char cmd[500]; sprintf(cmd, "touch %s_done", Get_String_Arg("-o")); system(cmd); return 0; }
int main(int argc, char *argv[]) { char puncta_swc_path[] = "/home/feng/otherSource/hand2.swc"; char puncta_meanshifted_swc_path[] = "/home/feng/otherSource/hand_meanshifted.swc"; char trace_result_path[] = "/home/feng/otherSource/015.trace/traced/"; char masked_swc_path[] = "/home/feng/otherSource/masked_hand.swc"; char masked_meanshifted_swc_path[] = "/home/feng/otherSource/masked_hand_meanshifted.swc"; char puncta_stack_path[] = "/home/feng/otherSource/C1-slice09_L5_Sum.tif"; int n; Locseg_Chain* chains = Dir_Locseg_Chain_N(trace_result_path, "^chain[[:digit:]]*\\.tb", &n, NULL); printf("found %d tb file\n", n); int i=0; Locseg_Label_Workspace* ws = New_Locseg_Label_Workspace(); Stack *mask = Make_Stack(GREY, 1024, 1024, 128); Zero_Stack(mask); double z_scale = 1; double pixelperumxy = 9.66; double pixelperumz = 2; double maskextendbyum = 2.5; double maskextendbypixel = maskextendbyum * pixelperumxy; for (i=0; i<n; i++) { Default_Locseg_Label_Workspace(ws); ws->option = 1; ws->sdiff = maskextendbypixel; ws->value = 255; Locseg_Chain_Label_W(&(chains[i]), mask, z_scale, 0, Locseg_Chain_Length(&(chains[i])), ws); } Write_Stack("/home/feng/otherSource/maskstack.tif", mask); Swc_Node *punctas = Read_Swc_File(puncta_swc_path, &n); printf("found %d puncta\n", n); FILE *fp = fopen(masked_swc_path, "w"); for (i=0; i<n; i++) { // if (*(STACK_PIXEL_8(mask, iround(punctas[i].x), iround(punctas[i].y), iround(punctas[i].z), 0)) == 255) { // Swc_Node_Fprint(fp, &(punctas[i])); // } if (Stack_Neighbor_Mean(mask, 26, iround(punctas[i].x), iround(punctas[i].y), iround(punctas[i].z)) > 0) { Swc_Node_Fprint(fp, &(punctas[i])); } } fclose(fp); fp = fopen(puncta_meanshifted_swc_path, "w"); Stack *puncta_stack = Read_Stack(puncta_stack_path); for (i=0; i<n; i++) { Geo3d_Ball *gb = New_Geo3d_Ball(); gb->center[0] = punctas[i].x; gb->center[1] = punctas[i].y; gb->center[2] = punctas[i].z; gb->r = 3; Geo3d_Ball_Mean_Shift(gb, puncta_stack, 1, 0.5); punctas[i].x = gb->center[0]; punctas[i].y = gb->center[1]; punctas[i].z = gb->center[2]; Swc_Node_Fprint(fp, punctas+i); Delete_Geo3d_Ball(gb); } fclose(fp); Kill_Stack(puncta_stack); fp = fopen(masked_meanshifted_swc_path, "w"); for (i=0; i<n; i++) { if (Stack_Neighbor_Mean(mask, 26, iround(punctas[i].x), iround(punctas[i].y), iround(punctas[i].z)) > 0) { Swc_Node_Fprint(fp, &(punctas[i])); } } fclose(fp); return 0; }
int main(int argc, const char *argv[]) { const char *dir_name = "/Users/zhaot/Data/nathan/2008-04-18"; if (argc > 1) { dir_name = argv[1]; } const char *result_dir = "/Users/zhaot/Work/V3D/neurolabi/data/align"; char filelist[100]; fullpath(result_dir, "filelist.txt", filelist); printf("%s\n", filelist); char file_path[150]; char image_path[150]; /* Read all files from the directory */ FILE *fp = fopen(filelist, "r"); char id[100]; int idx = 0; int idx2 = 0; int row = 22; int col = 15; #define MAX_FILE_NUMBER 364 char all_file[MAX_FILE_NUMBER][100]; double stack_mean[MAX_FILE_NUMBER]; int available[row * col]; while (Read_Word(fp, all_file[idx++], 0) > 0) { fullpath(dir_name, all_file[idx - 1], image_path); printf("%d, %s\n", idx, image_path); } fullpath(result_dir, "stack_mean.bn", file_path); if (!fexist(file_path)) { for (idx = 1; idx <= MAX_FILE_NUMBER; idx++) { fullpath(dir_name, all_file[idx - 1], image_path); Stack *stack = Read_Stack(image_path); stack_mean[idx - 1] = Stack_Mean(stack); printf("%d, %s: %g\n", idx, image_path, stack_mean[idx - 1]); Kill_Stack(stack); } darray_write(file_path, stack_mean, MAX_FILE_NUMBER); } else { int array_length; darray_read(file_path, stack_mean, &array_length); } if (idx - 1 != MAX_FILE_NUMBER) { fprintf(stderr, "Wrong file number: %d.\n", idx); } const double threshold = 115.0; for (idx = 0; idx < MAX_FILE_NUMBER; idx++) { if (stack_mean[idx] > threshold) { available[idx] = 1; } else { available[idx] = 0; } } for (idx = MAX_FILE_NUMBER; idx < row * col; idx++) { available[idx] = 0; } fullpath(result_dir, "align_input.txt", file_path); fclose(fp); int neighbor[] = {-1, 1, -22, 22}; fp = fopen(file_path, "w"); for (idx = 1; idx < MAX_FILE_NUMBER; idx++) { if (idx % row != 0) { if (available[idx - 1] && available[idx]) { fprintf(fp, "%s %s\n", all_file[idx - 1], all_file[idx]); align_id(all_file[idx - 1], all_file[idx], id); printf("%s\n", id); } } } int i, j; int offset = 0; for (j = 0; j < col - 1; j++) { offset = row * j; for (i = 0; i < row; i++) { idx = offset + i; idx2 = idx + row; if ((available[idx]) && (available[idx2])) { fprintf(fp, "%s %s\n", all_file[idx], all_file[idx2]); align_id(all_file[idx], all_file[idx2], id); printf("%s\n", id); break; } } } fclose(fp); return 1; }
int main(int argc, char *argv[]) { static char *Spec[] = {"[-t]", NULL}; Process_Arguments(argc, argv, Spec, 1); if (Is_Arg_Matched("-t")) { /* Example test */ Stack *stack = Make_Stack(GREY, 7, 7, 1); One_Stack(stack); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->conn = 26; ws->mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(ws->mask); /* set seeds */ Set_Stack_Pixel(ws->mask, 1, 1, 0, 0, 1.0); Set_Stack_Pixel(ws->mask, 1, 5, 0, 0, 2.0); Set_Stack_Pixel(ws->mask, 3, 3, 0, 0, 3.0); Set_Stack_Pixel(ws->mask, 5, 1, 0, 0, 4.0); Set_Stack_Pixel(ws->mask, 5, 5, 0, 0, 5.0); /* set stack values */ Set_Stack_Pixel(stack, 1, 1, 0, 0, 3.0); Set_Stack_Pixel(stack, 1, 5, 0, 0, 3.0); Set_Stack_Pixel(stack, 3, 3, 0, 0, 3.0); Set_Stack_Pixel(stack, 5, 1, 0, 0, 3.0); Set_Stack_Pixel(stack, 5, 5, 0, 0, 3.0); Stack *out = Stack_Watershed(stack, ws); //Write_Stack("../data/test/watershed/golden/watershed1.tif", out); char *golden_file = "../data/test/watershed/golden/watershed1.tif"; if (fexist(golden_file)) { Stack *golden = Read_Stack(golden_file); if (Stack_Identical(out, golden) == FALSE) { Print_Stack_Value(stack); Print_Stack_Value(out); Print_Stack_Value(golden); PRINT_EXCEPTION("Bug?", "Conflict with golden."); return 1; } Kill_Stack(stack); Kill_Stack(out); Kill_Stack(golden); Kill_Stack_Watershed_Workspace(ws); } else { printf("%s cannot be found.\n", golden_file); } char *test_file = "../data/benchmark/rice_label.tif"; if (fexist(test_file)) { stack = Read_Stack_U(test_file); ws = Make_Stack_Watershed_Workspace(stack); ws->mask = Copy_Stack(stack); ws->conn = 26; One_Stack(stack); out = Stack_Watershed(stack, ws); //Write_Stack("../data/test/watershed/golden/watershed2.tif", out); Stack *golden = Read_Stack("../data/test/watershed/golden/watershed2.tif"); if (Stack_Identical(out, golden) == FALSE) { PRINT_EXCEPTION("Bug?", "Conflict with golden."); return 1; } } else { printf("%s cannot be found.\n", test_file); } printf(":) Testing passed.\n"); return 0; } #if 0 /* Initialize */ Watershed_3d *watershed = New_Watershed_3d(); Watershed_3d_Workspace *ws = New_Watershed_3d_Workspace(); ws->conn = 26; /* Initialize stack */ Stack *stack = Read_Stack("../data/fly_neuron/dist.tif"); int nvoxel = Stack_Voxel_Number(stack); int i; uint16 *array16 = (uint16 *)stack->array; for (i = 0; i < nvoxel; i++) { array16[i] = 0xFFFF - array16[i]; } /* Add mask to ignore dark voxels */ ws->mask = Copy_Stack(stack); //Translate_Stack(stack, GREY, 1); //stack->array = stack->array + stack->width * stack->height * 100; //stack->depth = 1; // ws->mask = Copy_Stack(stack); //Stack_Binarize(ws->mask); // ws->mask = NULL; //Write_Stack("../data/dist.tif", stack); //Stack *stack2 = Copy_Stack(stack); # if 0 Build_3D_Watershed(stack, watershed, ws); Write_Stack("../data/test.tif", watershed->labels); # endif # if 0 Image_View iv = Image_View_Stack(stack2); Watershed_Test *watershed2 = Build_2D_Watershed_Test(&(iv.image), 0); Write_Image("../data/test2.tif", watershed2->labels); # endif #endif #if 0 Image *image = Read_Image("../data/Ring15.tif_Sub1200_Original_inv.tif"); Watershed_2D *ws = Build_2D_Watershed(image, 0); Image *result = Color_Watersheds(ws, image); Write_Image("../data/test.tif", result); Kill_Image(image); #endif #if 0 Stack *stack = Make_Stack(GREY, 7, 7, 1); One_Stack(stack); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->conn = 26; ws->mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(ws->mask); Set_Stack_Pixel(ws->mask, 1, 1, 0, 0, 1.0); Set_Stack_Pixel(ws->mask, 1, 5, 0, 0, 2.0); Set_Stack_Pixel(ws->mask, 3, 3, 0, 0, 3.0); Set_Stack_Pixel(ws->mask, 5, 1, 0, 0, 4.0); Set_Stack_Pixel(ws->mask, 5, 5, 0, 0, 5.0); Set_Stack_Pixel(stack, 1, 1, 0, 0, 3.0); Set_Stack_Pixel(stack, 1, 5, 0, 0, 3.0); Set_Stack_Pixel(stack, 3, 3, 0, 0, 3.0); Set_Stack_Pixel(stack, 5, 1, 0, 0, 3.0); Set_Stack_Pixel(stack, 5, 5, 0, 0, 3.0); Stack *out = Stack_Watershed(stack, ws); Print_Stack_Value(out); #endif #if 0 Stack *stack = Make_Stack(GREY, 3, 3, 1); One_Stack(stack); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->conn = 26; ws->mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(ws->mask); Set_Stack_Pixel(ws->mask, 0, 0, 0, 0, 1.0); Set_Stack_Pixel(ws->mask, 2, 2, 0, 0, 2.0); Set_Stack_Pixel(stack, 0, 0, 0, 0, 5.0); Set_Stack_Pixel(stack, 2, 2, 0, 0, 3.0); Set_Stack_Pixel(stack, 0, 2, 0, 0, 2.0); //Set_Stack_Pixel(stack, 1, 1, 0, 0, 2.0); Set_Stack_Pixel(stack, 1, 2, 0, 0, 2.0); Set_Stack_Pixel(stack, 2, 0, 0, 0, 2.0); Set_Stack_Pixel(stack, 2, 1, 0, 0, 2.0); Print_Stack_Value(stack); ws->start_level = 6; Stack *out = Stack_Watershed(stack, ws); Print_Stack_Value(out); #endif #if 0 Stack *stack = Read_Stack_U("../data/benchmark/rice_label.tif"); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->mask = Copy_Stack(stack); ws->conn = 26; One_Stack(stack); tic(); Stack *out = Stack_Watershed(stack, ws); printf("%lld\n", toc()); Write_Stack("../data/test.tif", out); #endif #if 0 Stack *stack = Read_Stack_U("../data/diadem_d1_147.xml"); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(ws->mask); ws->conn = 26; const int *dx = Stack_Neighbor_X_Offset(ws->conn); const int *dy = Stack_Neighbor_X_Offset(ws->conn); const int *dz = Stack_Neighbor_X_Offset(ws->conn); int seed[3]; String_Workspace *sw = New_String_Workspace(); char *line = NULL; FILE *fp = fopen("../data/diadem_d1_root_z.txt", "r"); int k = 1; while ((line = Read_Line(fp, sw)) != NULL) { int n; String_To_Integer_Array(line, seed, &n); double maxv = -1; if (n == 3) { maxv = Get_Stack_Pixel(stack, seed[0], seed[1], seed[2], 0); printf("%g\n", maxv); int i; for (i = 0; i < ws->conn; i++) { if (maxv < Get_Stack_Pixel(stack, seed[0] + dx[i], seed[1] + dy[i], seed[2] + dz[i], 0)) { maxv = Get_Stack_Pixel(stack, seed[0] + dx[i], seed[1] + dy[i], seed[2] + dz[i], 0); } } //Set_Stack_Pixel(stack, seed[0], seed[1], seed[2], 0, maxv); Set_Stack_Pixel(ws->mask, seed[0], seed[1], seed[2], 0, k); for (i = 0; i < ws->conn; i++) { //Set_Stack_Pixel(stack, seed[0] + dx[i], seed[1] + dy[i], // seed[2] + dz[i], 0, maxv); Set_Stack_Pixel(ws->mask, seed[0] + dx[i], seed[1] + dy[i], seed[2] + dz[i], 0, k); } k++; } } fclose(fp); Kill_String_Workspace(sw); /* Set_Stack_Pixel(ws->mask, 19, 605, 112, 0, 1.0); Set_Stack_Pixel(ws->mask, 28, 565, 112, 0, 1.0); */ Stack_Watershed_Infer_Parameter(stack, ws); tic(); Stack *out = Stack_Watershed(stack, ws); printf("%lld\n", toc()); Write_Stack("../data/diadem_d1_147_label.tif", out); static const uint8 Color_Map[][3] = { {0, 0, 0}, {0, 224, 64}, {32, 64, 128}, {64, 64, 0}, {64, 128, 64}, {96, 64, 128}, {64, 0, 0}, {128, 200, 64}, {160, 128, 128}, {192, 0, 0}, {192, 160, 64}, {224, 64, 128}, {224, 224, 192}}; Translate_Stack(out, COLOR, 1); size_t nvoxel = Stack_Voxel_Number(out); size_t i; color_t *arrayc = (color_t*) out->array; for (i = 0; i < nvoxel; i++) { arrayc[i][2] = Color_Map[arrayc[i][0]][2]; arrayc[i][1] = Color_Map[arrayc[i][0]][1]; arrayc[i][0] = Color_Map[arrayc[i][0]][0]; } Write_Stack("../data/diadem_d1_147_paint.tif", out); #endif #if 0 Stack *stack = Read_Stack_U("../data/diadem_d1_146.xml"); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); Stack *mask = Read_Stack("../data/test3.tif"); ws->mask = Crop_Stack(mask, 252, -937, 2, 1024, 1024, 63, NULL); ws->conn = 26; Stack_Watershed_Infer_Parameter(stack, ws); tic(); Stack *out = Stack_Watershed(stack, ws); printf("%lld\n", toc()); Write_Stack("../data/test2.tif", out); #endif #if 0 Stack *stack = Make_Stack(GREY, 7, 7, 1); One_Stack(stack); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->conn = 26; ws->mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(ws->mask); Set_Stack_Pixel(ws->mask, 1, 1, 0, 0, 1.0); Set_Stack_Pixel(ws->mask, 1, 5, 0, 0, 2.0); Set_Stack_Pixel(ws->mask, 3, 3, 0, 0, 3.0); Set_Stack_Pixel(ws->mask, 5, 1, 0, 0, 4.0); Set_Stack_Pixel(ws->mask, 5, 5, 0, 0, 5.0); Set_Stack_Pixel(stack, 1, 1, 0, 0, 3.0); Set_Stack_Pixel(stack, 1, 5, 0, 0, 3.0); Set_Stack_Pixel(stack, 3, 3, 0, 0, 3.0); Set_Stack_Pixel(stack, 5, 1, 0, 0, 3.0); Set_Stack_Pixel(stack, 5, 5, 0, 0, 3.0); Stack *out = Stack_Watershed(stack, ws); Print_Stack_Value(out); Stack *out2 = Stack_Region_Border_Shrink(out, ws); Print_Stack_Value(out2); #endif #if 0 Stack *stack = Read_Stack("../data/diadem_d1_013_label.tif"); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); //ws->conn = 26; Stack *out = Stack_Region_Border_Shrink(stack, ws); Write_Stack("../data/test.tif", out); #endif #if 0 Stack *stack = Make_Stack(GREY, 1, 1, 19); One_Stack(stack); stack->array[3] = 5; stack->array[4] = 5; stack->array[7] = 5; stack->array[8] = 5; stack->array[10] = 4; stack->array[11] = 5; stack->array[12] = 5; stack->array[13] = 4; stack->array[16] = 5; stack->array[17] = 5; Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->conn = 26; ws->mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(ws->mask); Print_Stack_Value(stack); Stack_Watershed_Zgap_Barrier(stack, ws->mask); Print_Stack_Value(ws->mask); #endif #if 0 Stack *stack = Read_Stack("../data/diadem_d1_047_label.tif"); Stack_Binarize(stack); Stack *stack2 = Stack_Bwdist_L_U16(stack, NULL, 0); Write_Stack("../data/test.tif", stack2); #endif #if 0 char stack_path[100]; char mask_path[100]; strcpy(stack_path, "../data/diadem_d1_064.xml"); strcpy(mask_path, stack_path); strsplit(mask_path, '.', -1); sprintf(mask_path, "%s_label.tif", mask_path); if (!fexist(stack_path)) { fprintf(stderr, "Cannot find %s\n", stack_path); return 1; } printf("Processing %s\n", stack_path); Stack *stack = Read_Stack_U(stack_path); Stack *mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(mask); int conn = 26; const int *dx = Stack_Neighbor_X_Offset(conn); const int *dy = Stack_Neighbor_X_Offset(conn); const int *dz = Stack_Neighbor_X_Offset(conn); int seed[3]; String_Workspace *sw = New_String_Workspace(); char *line = NULL; FILE *fp = fopen("../data/064.seeds.txt", "r"); int k = 1; /* label seeds */ while ((line = Read_Line(fp, sw)) != NULL) { int n; String_To_Integer_Array(line, seed, &n); double maxv = -1; if (n == 3) { maxv = Get_Stack_Pixel(stack, seed[0], seed[1], seed[2], 0); int i; for (i = 0; i < conn; i++) { if (maxv < Get_Stack_Pixel(stack, seed[0] + dx[i], seed[1] + dy[i], seed[2] + dz[i], 0)) { maxv = Get_Stack_Pixel(stack, seed[0] + dx[i], seed[1] + dy[i], seed[2] + dz[i], 0); } } Set_Stack_Pixel(mask, seed[0], seed[1], seed[2], 0, k); for (i = 0; i < conn; i++) { Set_Stack_Pixel(mask, seed[0] + dx[i], seed[1] + dy[i], seed[2] + dz[i], 0, k); } k++; } } fclose(fp); Kill_String_Workspace(sw); Stack_Running_Median(stack, 0, stack); Stack_Running_Median(stack, 1, stack); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->mask = mask; Filter_3d *filter = Gaussian_Filter_3d(2.0, 2.0, 1.5); Stack *filtered_stack = Filter_Stack(stack, filter); Stack_Watershed_Zgap_Barrier(filtered_stack, ws->mask); Stack_Running_Max(ws->mask, 0, ws->mask); Stack_Running_Max(ws->mask, 1, ws->mask); //Write_Stack("../data/test.tif", ws->mask); Kill_Stack(filtered_stack); filtered_stack = NULL; FMatrix *dm = Mexihat_3D1_F(2.0, NULL, 2); //FMatrix *dm = Mexihat_3D_F(2.0, NULL); FMatrix_Negative(dm); filtered_stack = Filter_Stack(stack, dm); Stack_Threshold_Common(filtered_stack, 0, 65535); Stack_Binarize(filtered_stack); Translate_Stack(filtered_stack, GREY, 1); { int i, j, k; int offset = 0; uint16 *array = (uint16*) stack->array; for (k = 0; k < stack->depth; k++) { for (j = 0; j < stack->height; j++) { for (i = 0; i < stack->width; i++) { if (filtered_stack != NULL) { if (filtered_stack->array[offset] == 1) { ws->mask->array[offset] = STACK_WATERSHED_BARRIER; } } array[offset++] += k * 2; } } } } Kill_Stack(filtered_stack); Stack_Watershed_Infer_Parameter(stack, ws); ws->conn = 6; double weights[26] = {0.5, 0.5, 1.0, 1.0, 0.2, 0.2, 0.75, 0.75, 0.75, 0.75, 0.35, 0.35, 0.35, 0.35, 0.6, 0.6, 0.6, 0.6, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45}; ws->weights = weights; ws->weights = NULL; if (ws->weights != NULL) { ws->min_level /= 3; } Stack_Running_Median(stack, 0, stack); Stack_Running_Median(stack, 1, stack); Stack *out = Stack_Watershed(stack, ws); strcpy(mask_path, stack_path); strsplit(mask_path, '.', -1); sprintf(mask_path, "%s_label.tif", mask_path); Write_Stack("../data/test.tif", out); #endif #if 0 Stack *stack = Read_Stack("../data/test/soma2.tif"); int thre = Stack_Find_Threshold_A(stack, THRESHOLD_LOCMAX_TRIANGLE); Filter_3d *filter = Gaussian_Filter_3d(1.0, 1.0, 0.5); Stack *out = Filter_Stack(stack, filter); stack = Copy_Stack(out); Stack_Threshold_Binarize(out, thre); Stack *out2 = Stack_Bwdist_L_U16P(out, NULL, 0); int nvoxel = Stack_Voxel_Number(out); uint16_t *dist_array = (uint16_t*) out2->array; int i; for (i = 0; i < nvoxel; i++) { dist_array[i] = sqrt(dist_array[i]); } Write_Stack("../data/labmeeting13/distp.tif", out2); #endif #if 0 //Stack *stack = Read_Stack("../data/test/soma2.tif"); Stack *stack = Read_Stack("/Users/zhaot/Data/jinny/slice7_2to34ds_soma_c2.tif"); int thre = Stack_Find_Threshold_A(stack, THRESHOLD_LOCMAX_TRIANGLE); Filter_3d *filter = Gaussian_Filter_3d(1.0, 1.0, 0.5); Stack *out = Filter_Stack(stack, filter); stack = Copy_Stack(out); Stack_Threshold_Binarize(out, thre); Stack *out2 = Stack_Bwdist_L_U16P(out, NULL, 0); /* out = Stack_Locmax_Region(out2, 26); */ Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(ws->mask); size_t nvoxel = Stack_Voxel_Number(stack); size_t offset; uint16_t *dist_array = (uint16_t*) out2->array; for (offset = 0; offset < nvoxel; offset++) { if (/*(out->array[offset] == 1) && */(dist_array[offset] > 1000)) { ws->mask->array[offset] = 1; } } //Objlabel_Workspace *ow = New_Objlabel_Workspace(); //Stack_Label_Large_Objects_W(ws->mask, 1, 2, 10, ow); //Stack_Label_Objects_N(ws->mask, NULL, 1, 2, 26); Object_3d_List *objs = Stack_Find_Object(ws->mask, 1, 100); Zero_Stack(ws->mask); Stack_Draw_Objects_Bw(ws->mask, objs, -255); printf("%g\n", Stack_Max(ws->mask, NULL)); /* Write_Stack("../data/test.tif", ws->mask); return 1; */ ws->min_level = thre; ws->start_level = 65535; Stack *out3 = Stack_Watershed(stack, ws); /* Write_Stack("../data/labmeeting13/watershed.tif", out3); return 1; */ for (offset = 0; offset < nvoxel; offset++) { if (dist_array[offset] < 300) { out3->array[offset] = 0; } } int nregion = Stack_Max(out3, NULL); Kill_Stack(out2); Stack *filtered = Copy_Stack(stack); Kill_Stack(stack); ws->conn = 8; stack = Stack_Region_Border_Shrink(out3, ws); out2 = Stack_Region_Expand(stack, 4, 30, NULL); for (offset = 0; offset < nvoxel; offset++) { if (out->array[offset] == 0) { out2->array[offset] = 0; } } Write_Stack("../data/test2.tif", out2); Kill_Stack(stack); //stack = Read_Stack("../data/test/soma2.tif"); stack = Read_Stack("/Users/zhaot/Data/jinny/slice7_2to34ds_soma_c2.tif"); Translate_Stack(stack, COLOR, 1); int i; double h = 0.0; double s = 1.0; for (i = 0; i < nregion; i++) { Stack_Label_Color_L(stack, out2, i+1, h+=0.35, s, filtered); /* Rgb_Color color; Set_Color_Jet(&color, i*3); Stack_Label_Level(stack, out2, i+1, color); */ } Write_Stack("../data/test.tif", stack); #endif #if 0 Stack *stack = Read_Stack("../data/leaktest/leak3.tif"); Stack *distmap = Stack_Bwdist_L_U16P(stack, NULL, 0); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->mask = Copy_Stack(distmap); Stack_Threshold_Binarize(ws->mask, 10); Translate_Stack(ws->mask, GREY, 1); Object_3d_List *objs = Stack_Find_Object(ws->mask, 1, 100); Zero_Stack(ws->mask); Stack_Draw_Objects_Bw(ws->mask, objs, -255); ws->min_level = 1; ws->start_level = 65535; Stack *out3 = Stack_Watershed(distmap, ws); Write_Stack("../data/test.tif", out3); #endif #if 0 Stack *stack = Read_Stack("../data/benchmark/two_disk.tif"); Stack_Watershed_Workspace *ws = Make_Stack_Watershed_Workspace(stack); ws->conn = 26; Stack *out = Stack_Watershed(stack, ws); Write_Stack("../data/test.tif", out); #endif return 0; }
int main(int argc, char *argv[]) { static char *Spec[] = {"[-t]", NULL}; Process_Arguments(argc, argv, Spec, 1); if (Is_Arg_Matched("-t")) { coordinate_3d_t coord = {0, 0, 0}; /* Translate coordinates. */ Geo3d_Translate_Coordinate(coord, coord+1, coord+2, 1.0, 2.0, 3.0); if ((coord[0] != 1.0) || (coord[1] != 2.0) || (coord[2] != 3.0)) { Print_Coordinate_3d(coord); PRINT_EXCEPTION(":( Bug?", "Unexpected coordinate values."); return 1; } coordinate_3d_t coord2 = {0, 0, 0}; double dx, dy, dz; Geo3d_Coordinate_Offset(coord[0], coord[1], coord[2], coord2[0], coord2[1], coord2[2], &dx, &dy, &dz); if ((dx != -coord[0]) || (dy != -coord[1]) || (dz != -coord[2])) { PRINT_EXCEPTION(":( Bug?", "Unexpected offset values."); return 1; } Coordinate_3d_Copy(coord2, coord); /* Rotate coordinates. */ Geo3d_Rotate_Coordinate(coord, coord+1, coord+2, 0.1, 0.5, 0); if (fabs(Geo3d_Orgdist_Sqr(coord[0], coord[1], coord[2]) - Geo3d_Orgdist_Sqr(coord2[0], coord2[1], coord2[2])) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Rotation failed."); return 1; } /* inverse rotation */ Geo3d_Rotate_Coordinate(coord, coord+1, coord+2, 0.1, 0.5, 1); if ((fabs(coord[0] - coord2[0]) > 0.01) || (fabs(coord[1] - coord2[1]) > 0.01) || (fabs(coord[2] - coord2[2]) > 0.01)){ PRINT_EXCEPTION(":( Bug?", "Rotation failed."); return 1; } /* Normal vector of an orientation. This is a canonical representaion * of an orientation. */ Geo3d_Orientation_Normal(0.1, 0.5, coord, coord+1, coord+2); /* We can also turn the normal vector into orientation. */ double theta, psi; Geo3d_Normal_Orientation(coord[0], coord[1], coord[2], &theta, &psi); if (fabs(theta - 0.1) > 0.01 || fabs(Normalize_Radian(psi) - 0.5) > 0.01) { printf("%g, %g\n", theta, psi); PRINT_EXCEPTION(":( Bug?", "Unexpected orientation values."); return 1; } /* If we rotate the vector back, we should get (0, 0, 1). */ Geo3d_Rotate_Coordinate(coord, coord+1, coord+2, 0.1, 0.5, 1); if ((fabs(coord[0]) > 0.01) || (fabs(coord[1]) > 0.01) || (fabs(coord[2] - 1.0) > 0.01)){ PRINT_EXCEPTION(":( Bug?", "Rotation failed."); return 1; } Geo3d_Coord_Orientation(1, 0, 0, &theta, &psi); double in[3] = {0, 0, 1}; double out[3] = {0, 0, 0}; Rotate_XZ(in, out, 1, theta, psi, 0); if (fabs(out[0] - 1.0) > 0.01 || fabs(out[1]) > 0.01 || fabs(out[2]) > 0.01) { printf("%g, %g, %g\n", out[0], out[1], out[2]); printf("%g, %g\n", theta, psi); PRINT_EXCEPTION(":( Bug?", "Unexpected orientation values."); return 1; } /* if (fabs(theta - TZ_PI_2) > 0.01 || fabs(Normalize_Radian(psi) - TZ_PI_2) > 0.01) { printf("%g, %g\n", theta, psi); PRINT_EXCEPTION(":( Bug?", "Unexpected orientation values."); return 1; } */ Geo3d_Coord_Orientation(5, 0, 0, &theta, &psi); { double in[3] = {0, 0, 5}; double out[3] = {0, 0, 0}; Rotate_XZ(in, out, 1, theta, psi, 0); if (fabs(out[0] - 5.0) > 0.01 || fabs(out[1]) > 0.01 || fabs(out[2]) > 0.01) { printf("%g, %g, %g\n", out[0], out[1], out[2]); printf("%g, %g\n", theta, psi); PRINT_EXCEPTION(":( Bug?", "Unexpected orientation values."); return 1; } } /* if (fabs(theta - TZ_PI_2) > 0.01 || fabs(Normalize_Radian(psi) - TZ_PI_2) > 0.01) { printf("%g, %g\n", theta, psi); PRINT_EXCEPTION(":( Bug?", "Unexpected orientation values."); return 1; } */ /* Rotate the orientation. */ theta = TZ_PI_2; psi = TZ_PI; Geo3d_Rotate_Orientation(-TZ_PI, TZ_PI_2, &theta, &psi); if (fabs(theta + TZ_PI_2) > 0.01 || fabs(psi + TZ_PI_2) > 0.01) { printf("%g, %g\n", theta, psi); PRINT_EXCEPTION(":( Bug?", "Unexpected orientation values."); return 1; } /* More extensive test on rotation */ Random_Seed(time(NULL) - getpid()); int i; for (i = 0; i < 100; i++) { double x = Unifrnd() * (1 - Bernrnd(0.5) * 2.0); double y = Unifrnd() * (1 - Bernrnd(0.5) * 2.0); double z = Unifrnd() * (1 - Bernrnd(0.5) * 2.0); double theta, psi; Geo3d_Coord_Orientation(x, y, z, &theta, &psi); double x2 = 0.0; double y2 = 0.0; double z2 = Geo3d_Orgdist(x, y, z); Geo3d_Rotate_Coordinate(&x2, &y2, &z2, theta, psi, 0); if (fabs(x - x2) > 0.01 || fabs(y - y2) > 0.01 || fabs(z - z2) > 0.01) { printf("%g, %g\n", theta, psi); printf("%g, %g, %g\n", x, y, z); printf("%g, %g, %g\n", x2, y2, z2); PRINT_EXCEPTION(":( Bug?", "Unexpected orientation values."); return 1; } } /* Dot product. */ if (Geo3d_Dot_Product(1.0, 2.0, 3.0, 3.0, 2.0, 1.0) != 10.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected dot product."); return 1; } /* Cross product. */ Geo3d_Cross_Product(1.0, 2.0, 3.0, 3.0, 1.0, 2.0, coord, coord+1, coord+2); if (fabs(Geo3d_Dot_Product(1.0, 2.0, 3.0, coord[0], coord[1], coord[2])) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected dot product."); return 1; } if (fabs(Geo3d_Dot_Product(3.0, 1.0, 2.0, coord[0], coord[1], coord[2])) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected dot product."); return 1; } /* Distance calculations. */ if (Geo3d_Orgdist_Sqr(1.0, 2.0, 3.0) != 14.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected value."); return 1; } if (fabs(Geo3d_Orgdist(1.0, 2.0, 3.0) - sqrt(14.0)) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected value."); return 1; } if (Geo3d_Dist(1.0, 2.0, 3.0, 1.0, 2.0, 3.0) != 0.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected value."); return 1; } if (Geo3d_Dist_Sqr(1.0, 2.0, 3.0, 0.0, 0.0, 0.0) != 14.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected value."); return 1; } /* Angle between two vectors. */ if (fabs(Geo3d_Angle2(1, 0, 0, 0, 0, 1) - TZ_PI_2) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected value."); return 1; } /* Distance between two lines */ coordinate_3d_t line1_start = {0, 0, 0}; coordinate_3d_t line1_end = {1, 0, 0}; coordinate_3d_t line2_start = {0, 1, 1}; coordinate_3d_t line2_end = {0, 2, 1}; double d = Geo3d_Line_Line_Dist(line1_start, line1_end, line2_start, line2_end); if (fabs(d - 1.0) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected distance."); return 1; } /* Distance between two line segments. */ double intersect1, intersect2; int cond; d = Geo3d_Lineseg_Lineseg_Dist(line1_start, line1_end, line2_start, line2_end, &intersect1, &intersect2, &cond); if (fabs(d - sqrt(2.0)) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected distance."); return 1; } /* Distance between a point and a line segment. */ coord[0] = 0.5; coord[1] = 1.0; coord[2] = 1.0; d = Geo3d_Point_Lineseg_Dist(coord, line1_start, line1_end, &intersect1); if (fabs(d - sqrt(2.0)) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected distance."); return 1; } /* Get a break point of a line segment. */ Geo3d_Lineseg_Break(line1_start, line1_end, 0.1, coord); if ((coord[0] != 0.1) || (coord[1] != 0.0) || (coord[2] != 0.0)) { PRINT_EXCEPTION(":( Bug?", "Unexpected break point."); return 1; } /* Orientations of a set of points */ /* Orientation of a covariance matrix */ /* 3D coordinates routines */ /* Unitize a point. */ Coordinate_3d_Unitize(coord); if (fabs(Coordinate_3d_Norm(coord) - 1.0) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected norm."); return 1; } Set_Coordinate_3d(coord, 0.0, 0.0, 0.0); /* origin point is not affected by unitization */ Coordinate_3d_Unitize(coord); if (Coordinate_3d_Norm(coord) != 0.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected norm."); return 1; } Set_Coordinate_3d(coord, 1.0, 2.0, 3.0); /* Square length */ if (Coordinate_3d_Length_Square(coord) != 14) { PRINT_EXCEPTION(":( Bug?", "Unexpected square length"); } /* Angle between two vectors */ coordinate_3d_t coord_a1 = { 1, 0, 0 }; coordinate_3d_t coord_a2 = { 0, 0, 1 }; if (fabs(Coordinate_3d_Angle2(coord_a1, coord_a2) - TZ_PI_2) > 0.01) { PRINT_EXCEPTION(":( Bug?", "Unexpected angle"); } /* Scale coordinates */ Coordinate_3d_Scale(coord, 2.0); if ((coord[0] != 2.0) || (coord[1] != 4.0) || (coord[2] != 6.0)) { PRINT_EXCEPTION(":( Bug?", "Unexpected coordinate value."); return 1; } /* Normalizd dot product */ if (Coordinate_3d_Normalized_Dot(coord, coord2) > 1.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected dot product."); return 1; } Set_Coordinate_3d(coord, 1.0, 2.0, 3.0); Coordinate_3d_Copy(coord2, coord); Coordinate_3d_Scale(coord2, 2.0); coordinate_3d_t coord3; Coordinate_3d_Copy(coord3, coord); Coordinate_3d_Scale(coord3, 3.0); /* cos value of an angle formed by 3 points */ if (Coordinate_3d_Cos3(coord, coord2, coord3) != 1.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected cos value."); return 1; } /* cos value of an angle formed by 4 points */ coordinate_3d_t coord4; Coordinate_3d_Copy(coord4, coord); Coordinate_3d_Scale(coord4, 4.0); if (Coordinate_3d_Cos4(coord, coord2, coord3, coord4) != 1.0) { PRINT_EXCEPTION(":( Bug?", "Unexpected cos value."); return 1; } printf(":) Testing passed.\n"); return 0; } #if 0 Geo3d_Vector v1 = {1.1, 0, 0}; Geo3d_Vector v2 = {5, 0, 0}; double theta1 = 3.83812; double psi1 = 3.53202; double theta2 = 0.72657; double psi2 = 3.61214; Geo3d_Orientation_Normal(theta1, psi1, &(v1.x), &(v1.y), &(v1.z)); Geo3d_Orientation_Normal(theta2, psi2, &(v2.x), &(v2.y), &(v2.z)); Print_Geo3d_Vector(&v1); Print_Geo3d_Vector(&v2); printf("%g\n", Geo3d_Vector_Dot(&v1, &v2)); printf("%g\n", Geo3d_Vector_Angle2(&v1, &v2)); double angle = Vector_Angle(-1.0, -1.0); theta1 = -3.0; psi1 = -5.0; double x, y, z; Geo3d_Orientation_Normal(theta1, psi1, &x, &y, &z); printf("%g, %g, %g\n", x, y, z); Geo3d_Normal_Orientation(x, y, z, &theta1, &psi1); printf("%g\n", angle * 180.0 / TZ_PI); printf("%g, %g\n", theta1, psi1); Geo3d_Orientation_Normal(theta1, psi1, &x, &y, &z); printf("%g, %g, %g\n", x, y, z); #endif #if 0 Geo3d_Scalar_Field *field = Read_Geo3d_Scalar_Field("../data/mouse_neuron/seeds.bn"); Print_Geo3d_Scalar_Field_Info(field); Stack *stack = Read_Stack("../data/mouse_neuron/mask.tif"); Geo3d_Scalar_Field_Draw_Stack(field, stack, NULL, NULL); Write_Stack("../data/test.tif", stack); #endif #if 0 double line_start[3] = {2.0, 3.0, 4.0}; double line_end[3] = {1.0, 1.0, 6.0}; double point[3] = {10.5, 20.5, 40.7}; double lamda; printf("%g\n", Geo3d_Point_Lineseg_Dist(point, line_start, line_end, &lamda)); double line_point[3]; double length = sqrt(Geo3d_Dist_Sqr(line_start[0], line_start[1], line_start[2], line_end[0], line_end[1], line_end[2])); line_point[0] = line_start[0] + lamda * (line_end[0] - line_start[0]); line_point[1] = line_start[1] + lamda * (line_end[1] - line_start[1]); line_point[2] = line_start[2] + lamda * (line_end[2] - line_start[2]); printf("%g\n", lamda); printf("%g\n", sqrt(Geo3d_Dist_Sqr(line_point[0], line_point[1], line_point[2], point[0], point[1], point[2]))); darray_sub(point, line_point, 3); darray_sub(line_end, line_point, 3); printf("%g\n", Geo3d_Dot_Product(point[0], point[1], point[2], line_end[0], line_end[1], line_end[2])); #endif #if 0 Geo3d_Scalar_Field *field = Read_Geo3d_Scalar_Field("../data/mouse_neuron3_org/seeds"); //Print_Geo3d_Scalar_Field(field); darray_write("../data/pts.bn", (double *)field->points, field->size * 3); darray_write("../data/ws.bn", field->values, field->size); coordinate_3d_t centroid; Geo3d_Scalar_Field_Centroid(field, centroid); Print_Coordinate_3d(centroid); double cov[9]; Geo3d_Scalar_Field_Cov(field, cov); darray_print2(cov, 3, 3); darray_write("../data/cov.bn", cov, 9); double vec[3]; Geo3d_Cov_Orientation(cov, vec); darray_print2(vec, 3, 1); #endif #if 0 double mu1, mu2; # if 0 /* parallel case */ double line1_start[3] = {0, 0, 0}; double line1_end[3] = {1, 1, 10}; double line2_start[3] = {0, 1, 0}; double line2_end[3] = {1, 2, 10}; # endif # if 0 /* parallel case */ double line1_start[3] = {0, 0, 0}; double line1_end[3] = {1, 1, 10}; double line2_start[3] = {-1, -1, -1}; double line2_end[3] = {-3, -3, -21}; # endif # if 0 /* i-i case */ double line1_start[3] = {0, 0, 0}; double line1_end[3] = {3, 4, 5}; double line2_start[3] = {-1, 8, 9}; double line2_end[3] = {1, -3, -4}; # endif # if 0 /* point to line case */ double line1_start[3] = {3, 4, 5}; double line1_end[3] = {3, 4, 5}; double line2_start[3] = {-1, 8, 9}; double line2_end[3] = {1, -3, -4}; # endif # if 0 /* point to line case */ double line2_start[3] = {3, 4, 5}; double line2_end[3] = {3, 4, 5}; double line1_start[3] = {-1, 8, 9}; double line1_end[3] = {1, -3, -4}; # endif # if 0 /* point to line case */ double line2_start[3] = {3, 4, 5}; double line2_end[3] = {3, 4, 5}; double line1_start[3] = {-1, 8, 9}; double line1_end[3] = {-1, 8, 9}; # endif # if 0 double line1_start[3] = {256.062, 328.674, 67.9029}; double line1_end[3] = {246.162, 330.078, 67.9896}; double line2_start[3] = {262.368, 336.609, 68.3076}; double line2_end[3] = {259.956, 326.944, 67.4325}; # endif int cond; double dist = Geo3d_Lineseg_Lineseg_Dist(line1_start, line1_end, line2_start, line2_end, &mu1, &mu2, &cond); printf("%d, %g\n", cond, dist); dist = Geo3d_Line_Line_Dist(line1_start, line1_end, line2_start, line2_end); printf("%g\n", dist); #endif #if 1 double *d = Unifrnd_Double_Array(12000000, NULL); double *d2 = Unifrnd_Double_Array(12000000, NULL); tic(); Rotate_XZ(d, d, 4000000, 0.1, 0.2, 1); printf("%llu\n", toc()); tic(); Rotate_XZ2(d, d, 4000000, 0.1, 0.2, 0); printf("%llu\n", toc()); #endif #if 0 double d[3] = {0.1, 0.2, 0.3}; Rotate_XZ(d, d, 1, 0.1, 0.2, 0); darray_print2(d, 3, 1); #endif #if 0 printf("%g\n", Ellipse_Point_Distance(5, 5, 3, 5)); #endif #if 0 Geo3d_Ellipse *ellipse = New_Geo3d_Ellipse(); ellipse->scale = 0.5; ellipse->orientation[0] = 1.0; Print_Geo3d_Ellipse(ellipse); FILE *fp = fopen("../data/test.swc", "w"); Swc_Node node; Geo3d_Ellipse_To_Swc_Node(ellipse, 1, -1, 1.0, 2, &node); Swc_Node_Fprint(fp, &node); /* double pt[3] = {0.0, 0.0, 1.0}; printf("%g\n", Geo3d_Ellipse_Point_Distance(ellipse, pt)); */ Geo3d_Ellipse *ellipse2 = Copy_Geo3d_Ellipse(ellipse); ellipse2->center[0] += 10.0; ellipse2->orientation[0] = 2.0; ellipse2->radius += 3.0; Geo3d_Ellipse *ellipse3 = Geo3d_Ellipse_Interpolate(ellipse, ellipse2, 0.2, NULL); Geo3d_Ellipse_To_Swc_Node(ellipse3, 2, 1, 1.0, 2, &node); Swc_Node_Fprint(fp, &node); Geo3d_Ellipse_To_Swc_Node(ellipse2, 3, 2, 1.0, 2, &node); Swc_Node_Fprint(fp, &node); Print_Geo3d_Ellipse(ellipse3); fclose(fp); #endif #if 0 Geo3d_Ellipse *ellipse = New_Geo3d_Ellipse(); ellipse->scale = 0.5; FILE *fp = fopen("../data/test.swc", "w"); coordinate_3d_t *pts = Geo3d_Ellipse_Sampling(ellipse, 20, 0, NULL); Geo3d_Point_Array_Swc_Fprint(fp, pts, 20, 1, -1, 1.0, 2); ellipse->orientation[0] = 1.0; pts = Geo3d_Ellipse_Sampling(ellipse, 20, 0, NULL); Geo3d_Point_Array_Swc_Fprint(fp, pts, 20, 21, -1, 1.0, 3); ellipse->center[2] = 5.0; pts = Geo3d_Ellipse_Sampling(ellipse, 20, 0, NULL); Geo3d_Point_Array_Swc_Fprint(fp, pts, 20, 41, -1, 1.0, 4); coordinate_3d_t vec[2]; Coordinate_3d_Copy(vec[0], ellipse->center); Geo3d_Ellipse_First_Vector(ellipse, vec[1]); Coordinate_3d_Add(vec[0], vec[1], vec[1]); Geo3d_Point_Array_Swc_Fprint(fp, vec, 2, 101, -1, 1.0, 5); Geo3d_Ellipse_Second_Vector(ellipse, vec[1]); Coordinate_3d_Add(vec[0], vec[1], vec[1]); Geo3d_Point_Array_Swc_Fprint(fp, vec, 2, 111, -1, 1.0, 6); Geo3d_Ellipse_Normal_Vector(ellipse, vec[1]); Coordinate_3d_Add(vec[0], vec[1], vec[1]); Geo3d_Point_Array_Swc_Fprint(fp, vec, 2, 121, -1, 1.0, 7); fclose(fp); #endif #if 0 Geo3d_Ellipse ep_array[10]; Geo3d_Ellipse *ellipse = New_Geo3d_Ellipse(); ellipse->scale = 0.5; Geo3d_Ellipse_Copy(ep_array, ellipse); FILE *fp = fopen("../data/test.swc", "w"); ellipse->orientation[0] += 0.5; ellipse->center[2] += 3.0; ellipse->center[0] += 1.0; Geo3d_Ellipse_Copy(ep_array + 1, ellipse); ellipse->center[2] += 3.0; Geo3d_Ellipse_Copy(ep_array + 2, ellipse); coordinate_3d_t *pts = Geo3d_Ellipse_Array_Sampling(ep_array, 3, 20, NULL); Geo3d_Point_Array_Swc_Fprint(fp, pts, 60, 1, -1, 1.0, 2); fclose(fp); #endif #if 0 printf("%g\n", Vector_Angle(1.0, 1.0) * 180 / TZ_PI); #endif #if 0 double theta, psi; coordinate_3d_t coord; coord[0] = 0.0822; coord[1] = 0.1515; coord[2] = 0.1369; Geo3d_Coord_Orientation(coord[0], coord[1], coord[2], &theta, &psi); printf("%g, %g\n", theta, psi); Geo3d_Orientation_Normal(theta, psi, coord, coord+1, coord+2); Print_Coordinate_3d(coord); #endif #if 0 double theta, psi; double x = -1; double y = 1.83697019872103e-16; double z = 3; Geo3d_Coord_Orientation(x, y, z, &theta, &psi); #endif #if 0 double theta = Vector_Angle2(0, 1, 1, 0, TRUE); printf("angle: %g\n", theta); theta = Vector_Angle2(0, 1, -1, 0, FALSE); printf("angle: %g\n", theta); theta = Vector_Angle2(-1, 0, -1, -1, TRUE); printf("angle: %g\n", theta); #endif return 0; }
/* * trace_neuron - trace neuron from given seeds * * trace_neuron [!wtr] seed_file -Dsave_dir * -r: write intermediate results * */ int main(int argc, char* argv[]) { static char *Spec[] = { "[!wtr] [-canvas <string>] [-mask <string>] [-res <string>] [-minr <int>]", "-minlen <double>", " <image:string> -S<string> -D<string>", NULL}; Process_Arguments(argc, argv, Spec, 1); char *dir = Get_String_Arg("-D"); char file_path[100]; sprintf(file_path, "%s/%s", dir, Get_String_Arg("-S")); printf("%s\n", file_path); Geo3d_Scalar_Field *seed = Read_Geo3d_Scalar_Field(file_path); int idx; sprintf(file_path, "%s/%s.bn", dir, "max_r"); double max_r; int tmp; if (fexist(file_path)) { darray_read2(file_path, &max_r, &tmp); } else { max_r = darray_max(seed->values, seed->size, &idx); } printf("%g\n", max_r); max_r *= 1.5; /* sprintf(file_path, "%s/%s", dir, "soma0.bn"); if (!fexist(file_path)) { max_r *= 2.0; } */ Set_Neuroseg_Max_Radius(max_r); Stack *signal = Read_Stack(Get_String_Arg("image")); dim_type dim[3]; dim[0] = signal->width; dim[1] = signal->height; dim[2] = signal->depth; /* IMatrix *chord = Make_IMatrix(dim, 3); Stack *code = Make_Stack(GREY16, signal->width, signal->height, signal->depth); */ Rgb_Color color; Set_Color(&color, 255, 0, 0); Stack *canvas = NULL; char trace_file_path[100]; sprintf(trace_file_path, "%s/%s", dir, Get_String_Arg("-canvas")); if (fexist(trace_file_path) == 1) { canvas = Read_Stack((char *) trace_file_path); } else { canvas = Copy_Stack(signal); Stretch_Stack_Value_Q(canvas, 0.999); Translate_Stack(canvas, COLOR, 1); } Stack *traced = NULL; char trace_mask_path[100]; sprintf(trace_mask_path, "%s/%s", dir, Get_String_Arg("-mask")); if (fexist(trace_mask_path) == 1) { traced = Read_Stack((char *) trace_mask_path); } else { traced = Make_Stack(GREY, signal->width, signal->height, signal->depth); One_Stack(traced); } //Object_3d *obj = NULL; int seed_offset = -1; Neurochain *chain = NULL; double z_scale = 1.0; if (Is_Arg_Matched("-res")) { sprintf(file_path, "%s", Get_String_Arg("-res")); if (fexist(file_path)) { double res[3]; int length; darray_read2(file_path, res, &length); if (res[0] != res[1]) { perror("Different X-Y resolutions."); TZ_ERROR(ERROR_DATA_VALUE); } z_scale = res[0] / res[2]; } } //sprintf(file_path, "%s/%s", dir, Get_String_Arg("-M")); //Stack *stack = Read_Stack(file_path); tic(); FILE *fp = NULL; char chain_file_path[100]; char vrml_file_path[100]; double min_chain_length = 25.0; if (Is_Arg_Matched("-minlen")) { min_chain_length = Get_Double_Arg("-minlen"); } int *indices = iarray_malloc(seed->size); double *values = darray_malloc(seed->size); int i; Local_Neuroseg *locseg = (Local_Neuroseg *) malloc(seed->size * sizeof(Local_Neuroseg)); int index = 0; for (i = 0; i < seed->size; i++) { printf("-----------------------------> seed: %d / %d\n", i, seed->size); indices[i] = i; index = i; int x = (int) seed->points[index][0]; int y = (int) seed->points[index][1]; int z = (int) seed->points[index][2]; double width = seed->values[index]; chain = New_Neurochain(); seed_offset = Stack_Util_Offset(x, y, z, signal->width, signal->height, signal->depth); if (width < 3.0) { width += 0.5; } Set_Neuroseg(&(locseg[i].seg), width, width, 12.0, 0.0, 0.0, 0.0); double cpos[3]; cpos[0] = x; cpos[1] = y; cpos[2] = z; cpos[2] *= z_scale; Set_Neuroseg_Position(&(locseg[i]), cpos, NEUROSEG_CENTER); Stack_Fit_Score fs; fs.n = 1; fs.options[0] = 1; values[i] = Local_Neuroseg_Orientation_Search_C(&(locseg[i]), signal, z_scale, &fs); } darray_qsort(values, indices, seed->size); /* for (i = 0; i < seed->size; i++) { indices[i] = i; } darraycpy(values, seed->values, 0, seed->size); darray_qsort(values, indices, seed->size); */ int counter = 0; // for (i = seed->size - 1; i >= seed->size - 231; i--) { for (i = seed->size - 1; i >= 0; i--) { index = indices[i]; printf("-----------------------------> seed: %d / %d\n", i, seed->size); sprintf(chain_file_path, "%s/chain%d.bn", dir, index); sprintf(vrml_file_path, "%s/chain%d.wrl", dir, index); if (fexist(chain_file_path) == 1) { chain = Read_Neurochain(chain_file_path); if (Neurochain_Geolen(chain) >= min_chain_length) { Write_Neurochain_Vrml(vrml_file_path, chain); Neurochain_Label(canvas, chain, z_scale); Neurochain_Erase_E(traced, chain, z_scale, 0, Neurochain_Length(chain, FORWARD), 1.5, 0.0); } Free_Neurochain(chain); printf("chain exists\n"); continue; } int x = (int) seed->points[index][0]; int y = (int) seed->points[index][1]; int z = (int) seed->points[index][2]; if (*STACK_PIXEL_8(traced, x, y, z, 0) == 0) { printf("traced \n"); continue; } double width = seed->values[index]; if (width > max_r) { printf("too thick\n"); continue; } if (Is_Arg_Matched("-minr")) { int max_level = (int) (width + 0.5); if (max_level <= Get_Int_Arg("-minr")) { printf("too thin\n"); continue; } } /* seed_offset = Stack_Util_Offset(x, y, z, signal->width, signal->height, signal->depth); */ chain = New_Neurochain(); /* Stack_Level_Code_Constraint(stack, code, chord->array, &seed_offset, 1, max_level + 1); Voxel_t v; v[0] = x; v[1] = y; v[2] = z; Stack *tmp_stack = Copy_Stack(stack); obj = Stack_Grow_Object_Constraint(tmp_stack, 1, v, chord, code, max_level); Free_Stack(tmp_stack); Print_Object_3d_Info(obj); double vec[3]; Object_3d_Orientation_Zscale(obj, vec, MAJOR_AXIS, z_scale); double theta, psi; Geo3d_Vector obj_vec; Set_Geo3d_Vector(&obj_vec, vec[0], vec[1], vec[2]); Geo3d_Vector_Orientation(&obj_vec, &theta, &psi); */ /* if (width < 3.0) { width += 0.5; } Set_Neuroseg(&(chain->locseg.seg), width, width, 12.0, 0.0, 0.0, 0.0); double cpos[3]; cpos[0] = x; cpos[1] = y; cpos[2] = z; cpos[2] *= z_scale; //Set_Neuroseg_Position(&(chain->locseg), cpos, NEUROSEG_BOTTOM); Set_Neuroseg_Position(&(chain->locseg), cpos, NEUROSEG_CENTER); Stack_Fit_Score fs; fs.n = 1; fs.options[0] = 1; Local_Neuroseg_Orientation_Search_C(&(chain->locseg), signal, z_scale, &fs); //fs.options[0] = 1; */ Copy_Local_Neuroseg(&(chain->locseg), &(locseg[index])); Neurochain *chain_head = chain; if (Initialize_Tracing(signal, chain, NULL, z_scale) >= MIN_SCORE) { if ((Neuroseg_Hit_Traced(&(chain->locseg), traced, z_scale) == FALSE) && (chain->locseg.seg.r1 < max_r) && (chain->locseg.seg.r2 < max_r)) { //Initialize_Tracing(signal, chain, NULL, z_scale); chain = Trace_Neuron2(signal, chain, BOTH, traced, z_scale, 500); //Neurochain *chain_head = Neurochain_Head(chain); chain_head = Neurochain_Remove_Overlap_Segs(chain); chain_head = Neurochain_Remove_Turn_Ends(chain_head, 0.5); /* if (i == seed->size - 231) { Print_Neurochain(chain_head); } */ fp = fopen(chain_file_path, "w"); Neurochain_Fwrite(chain_head, fp); fclose(fp); if (Neurochain_Geolen(chain_head) >= min_chain_length) { Write_Neurochain_Vrml(vrml_file_path, chain_head); Neurochain_Erase_E(traced, chain_head, z_scale, 0, Neurochain_Length(chain_head, FORWARD), 1.5, 0.0); Neurochain_Label(canvas, chain_head, z_scale); counter += Neurochain_Length(chain_head, FORWARD); if (counter > 500) { if (Is_Arg_Matched("-r")) { Write_Stack((char *) trace_mask_path, traced); } if (Is_Arg_Matched("-r")) { Write_Stack((char *) trace_file_path, canvas); } counter = 0; } } } } Free_Neurochain(chain_head); //Kill_Object_3d(obj); } Write_Stack((char *) trace_file_path, canvas); if (Is_Arg_Matched("-r")) { Write_Stack((char *) trace_mask_path, traced); } Kill_Geo3d_Scalar_Field(seed); printf("Time passed: %lld\n", toc()); return 0; }
int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s/mask.tif", neuron_name); Stack *stack2 = Read_Stack(file_path); Stack *stack3 = Copy_Stack(stack2); sprintf(file_path, "../data/%s/blobmask.tif", neuron_name); Stack *stack1 = Read_Stack(file_path); Object_3d_List *objs = Stack_Find_Object_N(stack1, NULL, 1, 7, 26); sprintf(file_path, "../data/%s/holeimg.tif", neuron_name); Stack *hole_stack = Read_Stack(file_path); int value; int label = 2; char id_file_path[100]; sprintf(id_file_path, "../data/%s/region_id.txt", neuron_name); FILE *id_fp = fopen(id_file_path, "w"); while (objs != NULL) { int hole_area = Stack_Foreground_Area_O(hole_stack, objs->data); printf("%d / %lu\n", hole_area, objs->data->size); //if (hole_area > (int) ((double) (objs->data->size) * 0.01)) { if (hole_area > 100) { value = 3; } else { value = 2; } if (objs->data->size + hole_area < TZ_PI * 10.0 * 10.0) { TRACE("small object labeled"); } fprintf(id_fp, "%d %d\n", label, value); Stack_Draw_Object_Bw(stack3, objs->data, label++); Stack_Draw_Object_Bw(stack2, objs->data, value); objs = objs->next; } fprintf(id_fp, "-1 -1\n"); fclose(id_fp); sprintf(file_path, "../data/%s/soma.tif", neuron_name); Write_Stack(file_path, stack2); printf("%s (2: arbor, 3: soma) created.\n", file_path); sprintf(file_path, "../data/%s/region_label.tif", neuron_name); Write_Stack(file_path, stack3); printf("%s (one unique label for one region) created.\n", file_path); Kill_Stack(stack1); Kill_Stack(stack2); Kill_Stack(stack3); Kill_Stack(hole_stack); return 0; }
/** * Find the background of a tif stack. * Output : integer * Input : stack file or bundle file. */ void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { if (nrhs < 1 || nrhs > 3) mexErrMsgTxt("The function takes 1~3 arguments."); if ( !mxIsChar(prhs[0]) ) mexErrMsgTxt("The argument must be a string"); if (nrhs == 2) { if ( !tz_mxIsDoubleScalar(prhs[1]) ) mexErrMsgTxt("The second argument must be a doulbe scalar"); } if (nrhs == 3) { if ( !tz_mxIsDoubleScalar(prhs[2]) ) mexErrMsgTxt("The third argument must be a doulbe scalar"); } char *filePath = mxArrayToString(prhs[0]); Stack *stack = NULL; if( strlen(filePath)>4 ) { if( Is_Tiff(filePath) ) /* Read file */ stack = Read_Stack(filePath); else if ( Is_Fbdf(filePath) ) { /* Read directory */ File_Bundle fb; initfb(&fb); if( Load_Fbdf(filePath,&fb) ) stack = Read_Stack_Planes(&fb); freefb(&fb); } else mexErrMsgTxt("Unrecongnized file format."); } else { mexErrMsgTxt("Unrecongnized file format."); } if( stack==NULL ) mexErrMsgTxt("Unable to load the stack."); int *hist,com; int low,high; if( stack->kind==GREY || stack->kind==GREY16 ) { hist = Stack_Hist(stack); if (nrhs == 1) { low = hist[1]; high = hist[0]+hist[1]-1; } else if (nrhs == 2) { low = (int) (*mxGetPr(prhs[1])); high = hist[0]+hist[1]-1; } else { low = (int) (*mxGetPr(prhs[1])); high = (int) (*mxGetPr(prhs[2])); } printf("Pick threshold between %d and %d\n", low, high); com = Hist_Most_Common(hist,low,high); free(hist); Kill_Stack(stack); } else { Kill_Stack(stack); mexErrMsgTxt("Unsupported image format."); } uint8 *thre; uint16 *thre16; switch(stack->kind) { case GREY: plhs[0] = mxCreateNumericMatrix(1,1,mxUINT8_CLASS,mxREAL); thre = (uint8 *) mxGetPr(plhs[0]); *thre = com; break; case GREY16: plhs[0] = mxCreateNumericMatrix(1,1,mxUINT16_CLASS,mxREAL); thre16 = (uint16 *) mxGetPr(plhs[0]); *thre16 = com; break; defaut: Kill_Stack(stack); mexErrMsgTxt("Unsupported image format."); } }
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; }
int main(int argc, char *argv[]) { #if 0 Stack *stack = Read_Stack("../data/fly_neuron.tif"); Stretch_Stack_Value_Q(stack, 0.99); Translate_Stack(stack, GREY, 1); Write_Stack("../data/test.tif", stack); Kill_Stack(stack); #endif #if 0 int idx1, idx2, width, height; idx1 = 33332; idx2 = 65535; width = 111; height = 112; printf("%g\n", Stack_Util_Voxel_Distance(idx1, idx2, width, height)); int x1, y1, z1, x2, y2, z2; Stack_Util_Coord(idx1, width, height, &x1, &y1, &z1); Stack_Util_Coord(idx2, width, height, &x2, &y2, &z2); printf("%d, %d, %d\n", x1 - x2, y1 - y2, z1 - z2); #endif #if 0 Stack *stack = Read_Stack("../data/fly_neuron.tif"); //Translate_Stack(stack, GREY16, 1); Image *image = Proj_Stack_Zmax(stack); Write_Image("../data/test.tif", image); #endif #if 0 Stack *stack = Read_Stack("../data/fly_neuron_a1_org.tif"); //stack = Crop_Stack(stack, 256, 256, 0, 512, 512, 170, NULL); int i; Stack stack2; stack2.width = stack->width; stack2.height = stack->height; stack2.kind = stack->kind; stack2.depth = 1; for (i = 0; i < stack->depth; i++) { stack2.array = stack->array + i * stack->width * stack->height; //Stack *locmax = Stack_Locmax_Region(&stack2, 8); Stack *locmax = Stack_Local_Max(&stack2, NULL, STACK_LOCMAX_SINGLE); int *hist = Stack_Hist_M(&stack2, locmax); int low, high; Int_Histogram_Range(hist, &low, &high); int thre = Int_Histogram_Triangle_Threshold(hist, low, high); printf("Threshold: %d\n", thre); Stack_Threshold_Binarize(&stack2, thre); Kill_Stack(locmax); free(hist); } //Stack_Bc_Autoadjust(result); /* Translate_Stack(stack, COLOR, 1); Stack_Blend_Mc(stack, result, 0.1); */ Write_Stack("../data/test.tif", stack); #endif #if 1 Stack *stack = Read_Stack("../data/fly_neuron_crop.tif"); Filter_3d *filter = Gaussian_Filter_3d(1.0, 1.0, 0.5); Stack *out = Filter_Stack(stack, filter); Kill_FMatrix(filter) Write_Stack("../data/test.tif", out); #endif #if 0 Stack *stack = Read_Stack("../data/fly_neuron_a2_org.tif"); Stack *locmax = Stack_Locmax_Region(stack, 18); Stack *mask = Read_Stack("../data/fly_neuron_a2_org/threshold_s.tif"); //Stack_And(locmax, mask, locmax); Object_3d_List *objs = Stack_Find_Object_N(locmax, NULL, 1, 0, 18); Zero_Stack(locmax); int objnum = 0; while (objs != NULL) { Object_3d *obj = objs->data; Voxel_t center; Object_3d_Central_Voxel(obj, center); Set_Stack_Pixel(locmax, center[0], center[1], center[2], 0, 1); objs = objs->next; objnum++; } Write_Stack("../data/fly_neuron_a2_org/locmax.tif", locmax); printf("objnum: %d\n", objnum); U8Matrix mat; mat.ndim = 3; mat.dim[0] = stack->width; mat.dim[1] = stack->height; mat.dim[2] = stack->depth; mat.array = locmax->array; dim_type bdim[3]; bdim[0] = 7; bdim[1] = 7; bdim[2] = 5; U8Matrix *mat2 = U8Matrix_Blocksum(&mat, bdim, NULL); int offset[3]; offset[0] = bdim[0] / 2; offset[1] = bdim[1] / 2; offset[2] = bdim[2] / 2; Crop_U8Matrix(mat2, offset, mat.dim, &mat); Write_Stack("../data/fly_neuron_a2_org/locmax_sum.tif", locmax); Stack_Threshold_Binarize(locmax, 6); Stack *clear_stack = Stack_Majority_Filter_R(locmax, NULL, 26, 4); Struct_Element *se = Make_Cuboid_Se(3, 3, 3); Stack *dilate_stack = Stack_Dilate(clear_stack, NULL, se); Stack *fill_stack = Stack_Fill_Hole_N(dilate_stack, NULL, 1, 4, NULL); Kill_Stack(dilate_stack); Stack_Not(fill_stack, fill_stack); Stack_And(fill_stack, mask, mask); Write_Stack("../data/test.tif", mask); #endif #if 0 Stack *stack = Read_Stack("../data/fly_neuron_t1.tif"); Stack *locmax = Stack_Locmax_Region(stack, 6); Stack_Label_Objects_Ns(locmax, NULL, 1, 2, 3, 6); int nvoxel = Stack_Voxel_Number(locmax); int i; int s[26]; for (i = 0; i < nvoxel; i++) { if (locmax->array[i] < 3) { locmax->array[i] = 0; } else { locmax->array[i] = 1; printf("%u\n", stack->array[i]); Stack_Neighbor_Sampling_I(stack, 6, i, -1, s); iarray_print2(s, 6, 1); } } //Stack *locmax = Stack_Local_Max(stack, NULL, STACK_LOCMAX_SINGLE); Write_Stack("../data/test.tif", locmax); #endif #if 0 Stack *stack = Read_Stack("../data/fly_neuron_n1.tif"); Stack *stack2 = Flip_Stack_Y(stack, NULL); Flip_Stack_Y(stack2, stack2); if (!Stack_Identical(stack, stack2)) { printf("bug found\n"); } Write_Stack("../data/test.tif", stack); #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("../data/benchmark/L3_12bit.lsm", -1); Mc_Stack_Grey16_To_8(stack, 3); Write_Mc_Stack("../data/test.lsm", stack, "../data/benchmark/L3_12bit.lsm"); #endif #if 0 //Stack *stack = Read_Stack("../data/C2-Slice06_R1_GR1_B1_L18.tif"); Stack *stack = Read_Stack("../data/fly_neuron_n1/traced.tif"); Print_Stack_Info(stack); #endif #if 0 Mc_Stack *stack = Make_Mc_Stack(GREY, 1024, 1024, 1024, 5); /* stack.width = 1024; stack.height = 1024; stack.depth = 1024; stack.kind = GREY; stack.nchannel = 5; printf("%zd\n", ((size_t)stack.kind * stack.width * stack.height * stack.depth * stack.nchannel)); */ #endif #if 0 Stack *stack = Make_Stack(GREY, 1, 1, 1); printf("stack usage: %d\n", Stack_Usage()); uint8 *data = stack->array; stack->array = NULL; Kill_Stack(stack); stack = Read_Stack("../data/benchmark/line.tif"); free(data); printf("stack usage: %d\n", Stack_Usage()); #endif #if 0 Stack *stack = Read_Stack("../data/test.tif"); int *hist = Stack_Hist(stack); Print_Int_Histogram(hist); #endif #if 0 Stack *stack = Read_Stack("../data/benchmark/mouse_neuron_single/stack.tif"); Stack dst; dst.text = "\0"; dst.array = stack->array; Crop_Stack(stack, 0, 0, 0, stack->width - 100, stack->height - 100, stack->depth - 30, &dst); Write_Stack("../data/test.tif", &dst); #endif #if 0 Stack *stack = Make_Stack(GREY, 5, 5, 3); Zero_Stack(stack); Set_Stack_Pixel(stack, 2, 2, 1, 0, 1.0); Print_Stack_Value(stack); Stack *out = Stack_Running_Max(stack, 0, NULL); out = Stack_Running_Max(out, 1, out); out = Stack_Running_Max(out, 2, out); Print_Stack_Value(out); #endif #if 0 Stack *stack = Read_Stack("../data/benchmark/stack_graph/fork/fork.tif"); Stack *out = Stack_Running_Median(stack, 0, NULL); Stack_Running_Median(out, 1, out); //Stack_Running_Max(stack, 0, out); //Stack_Running_Max(out, 1, out); Write_Stack("../data/test.tif", out); Stack *out2 = Stack_Running_Median(stack, 0, NULL); Stack *out3 = Stack_Running_Median(out2, 1, NULL); if (Stack_Identical(out, out3)) { printf("Same in-place and out-place\n"); } #endif #if 0 Stack *stack = Read_Stack_U("../data/diadem_d1_147.xml"); printf("%d\n", Stack_Threshold_Quantile(stack, 0.9)); #endif #if 0 const char *filepath = "/Users/zhaot/Data/Julie/All_tiled_nsyb5_Sum.lsm"; char filename[100]; fname(filepath, filename); Mc_Stack *stack = Read_Mc_Stack(filepath, -1); Print_Mc_Stack_Info(stack); Mc_Stack *tmpstack = Make_Mc_Stack(stack->kind, stack->width, stack->height, stack->depth / 8, stack->nchannel); size_t channel_size = stack->kind * stack->width *stack->height * stack->depth; size_t channel_size2 = tmpstack->kind * tmpstack->width *tmpstack->height * tmpstack->depth; int i; int k; uint8_t *array = stack->array; for (k = 0; k < 8; k++) { int offset = 0; int offset2 = 0; for (i = 0; i < stack->nchannel; i++) { memcpy(tmpstack->array + offset2, array + offset, channel_size2); offset += channel_size; offset2 += channel_size2; } array += channel_size2; char outpath[500]; sprintf(outpath, "../data/test/%s_%03d.lsm", filename, k); Write_Mc_Stack(outpath, tmpstack, filepath); } #endif #if 0 Stack *stack = Index_Stack(GREY16, 5, 5, 1); Set_Stack_Pixel(stack, 1, 1, 0, 0, 0); Set_Stack_Pixel(stack, 1, 2, 0, 0, 0); Print_Stack_Value(stack); Stack *out = Stack_Neighbor_Median(stack, 8, NULL); Print_Stack_Value(out); #endif #if 0 Stack *stack = Make_Stack(GREY, 10, 10, 3); Zero_Stack(stack); Cuboid_I bound_box; Set_Stack_Pixel(stack, 1, 1, 1, 0, 1); Set_Stack_Pixel(stack, 1, 2, 1, 0, 1); Set_Stack_Pixel(stack, 3, 1, 2, 0, 1); Stack_Bound_Box(stack, &bound_box); Print_Cuboid_I(&bound_box); #endif #if 0 Stack_Document *doc = Xml_Read_Stack_Document("../data/test.xml"); File_List *list = (File_List*) doc->ci; Cuboid_I bound_box; Stack_Bound_Box_F(list, &bound_box); Print_Cuboid_I(&bound_box); #endif #if 0 Stack_Document *doc = Xml_Read_Stack_Document("../data/test.xml"); File_List *list = (File_List*) doc->ci; Print_File_List(list); Stack *stack = Read_Image_List_Bounded(list); Stack *out = stack; out = Stack_Region_Expand(stack, 8, 1, NULL); out = Downsample_Stack(out, 4, 4, 0); Write_Stack("../data/test.tif", out); #endif #if 0 Stack_Document *doc = Xml_Read_Stack_Document( "../data/ting_example_stack/test.xml"); File_List *list = (File_List*) doc->ci; Print_File_List(list); int i; for (i = 0; i < list->file_number; i++) { Stack *stack = Read_Stack_U(list->file_path[i]); Stack *ds = Downsample_Stack(stack, 39, 39, 0); char file_path[500]; sprintf(file_path, "../data/ting_example_stack/thumbnails/tb%05d.tif", i); Write_Stack(file_path, ds); Free_Stack(stack); } #endif #if 0 Stack *stack = Read_Stack("../data/test2.tif"); Stack_Threshold_Binarize(stack, 6); Objlabel_Workspace ow; STACK_OBJLABEL_OPEN_WORKSPACE(stack, (&ow)); Object_3d *obj = Stack_Find_Largest_Object_N(stack, ow.chord, 1, 26); //Print_Object_3d(obj); //printf("%llu\n", obj->size); double vec[3]; Object_3d_Orientation(obj, vec, MAJOR_AXIS); double center[3]; Object_3d_Centroid(obj, center); darray_print2(vec, 3, 1); double span[2] = {100000, -100000}; for (int i = 0; i < obj->size; i++) { double proj = Geo3d_Dot_Product(vec[0], vec[1], vec[2], (double) obj->voxels[i][0] - center[0], (double) obj->voxels[i][1] - center[1], (double) obj->voxels[i][2] - center[2]); if (proj < span[0]) { span[0] = proj; } if (proj > span[1]) { span[1] = proj; } } darray_print2(span, 2, 1); double vec2[3]; Object_3d_Orientation(obj, vec2, PLANE_NORMAL); darray_print2(vec2, 3, 1); double span2[2] = {100000, -100000}; for (int i = 0; i < obj->size; i++) { double proj = Geo3d_Dot_Product(vec2[0], vec2[1], vec2[2], (double) obj->voxels[i][0] - center[0], (double) obj->voxels[i][1] - center[1], (double) obj->voxels[i][2] - center[2]); if (proj < span2[0]) { span2[0] = proj; } if (proj > span2[1]) { span2[1] = proj; } } darray_print2(span2, 2, 1); double vec3[3]; Geo3d_Cross_Product(vec[0], vec[1], vec[2], vec2[0], vec2[1], vec2[2], vec3, vec3+1, vec3+2); double span3[2] = {100000, -100000}; int i; for (i = 0; i < obj->size; i++) { double proj = Geo3d_Dot_Product(vec3[0], vec3[1], vec3[2], (double) obj->voxels[i][0] - center[0], (double) obj->voxels[i][1] - center[1], (double) obj->voxels[i][2] - center[2]); if (proj < span3[0]) { span3[0] = proj; } if (proj > span3[1]) { span3[1] = proj; } } darray_print2(span3, 2, 1); coordinate_3d_t vertex[8]; for (i = 0; i < 8; i++) { Coordinate_3d_Copy(vertex[i], center); int j; for (j = 0; j < 3; j++) { vertex[i][j] += span[0] * vec[j] + span2[0] * vec2[j] + span3[0] * vec3[j]; } } for (i = 0; i < 3; i++) { vertex[1][i] += (span[1] - span[0]) * vec[i]; vertex[2][i] += (span2[1] - span2[0]) * vec2[i]; vertex[3][i] += (span3[1] - span3[0]) * vec3[i]; vertex[4][i] = vertex[1][i] + (span2[1] - span2[0]) * vec2[i]; vertex[5][i] = vertex[2][i] + (span3[1] - span3[0]) * vec3[i]; vertex[6][i] = vertex[3][i] + (span[1] - span[0]) * vec[i]; vertex[7][i] = vertex[5][i] + (span[1] - span[0]) * vec[i]; } FILE *fp = fopen("../data/test.swc", "w"); fprintf(fp, "%d %d %g %g %g %g %d\n", 1, 2, vertex[0][0], vertex[0][1], vertex[0][2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 2, 2, vertex[1][0], vertex[1][1], vertex[1][2], 3.0, 1); fprintf(fp, "%d %d %g %g %g %g %d\n", 3, 2, vertex[2][0], vertex[2][1], vertex[2][2], 3.0, 1); fprintf(fp, "%d %d %g %g %g %g %d\n", 4, 2, vertex[3][0], vertex[3][1], vertex[3][2], 3.0, 1); fprintf(fp, "%d %d %g %g %g %g %d\n", 5, 2, vertex[4][0], vertex[4][1], vertex[4][2], 3.0, 2); fprintf(fp, "%d %d %g %g %g %g %d\n", 6, 2, vertex[5][0], vertex[5][1], vertex[5][2], 3.0, 3); fprintf(fp, "%d %d %g %g %g %g %d\n", 7, 2, vertex[6][0], vertex[6][1], vertex[6][2], 3.0, 4); fprintf(fp, "%d %d %g %g %g %g %d\n", 8, 2, vertex[7][0], vertex[7][1], vertex[7][2], 3.0, 7); fprintf(fp, "%d %d %g %g %g %g %d\n", 9, 2, vertex[4][0], vertex[4][1], vertex[4][2], 3.0, 8); fprintf(fp, "%d %d %g %g %g %g %d\n", 10, 2, vertex[4][0], vertex[4][1], vertex[4][2], 3.0, 3); fprintf(fp, "%d %d %g %g %g %g %d\n", 11, 2, vertex[5][0], vertex[5][1], vertex[5][2], 3.0, 8); fprintf(fp, "%d %d %g %g %g %g %d\n", 12, 2, vertex[5][0], vertex[5][1], vertex[5][2], 3.0, 4); fprintf(fp, "%d %d %g %g %g %g %d\n", 13, 2, vertex[6][0], vertex[6][1], vertex[6][2], 3.0, 2); /* Geo3d_Scalar_Field *field = Make_Geo3d_Scalar_Field(6); field->points[0][0] = span[0] * vec[0] + center[0]; field->points[0][1] = span[0] * vec[1] + center[1]; field->points[0][2] = span[0] * vec[2] + center[2]; field->points[1][0] = span[1] * vec[0] + center[0]; field->points[1][1] = span[1] * vec[1] + center[1]; field->points[1][2] = span[1] * vec[2] + center[2]; field->points[2][0] = span2[0] * vec2[0] + center[0]; field->points[2][1] = span2[0] * vec2[1] + center[1]; field->points[2][2] = span2[0] * vec2[2] + center[2]; field->points[3][0] = span2[1] * vec2[0] + center[0]; field->points[3][1] = span2[1] * vec2[1] + center[1]; field->points[3][2] = span2[1] * vec2[2] + center[2]; field->points[4][0] = span3[0] * vec3[0] + center[0]; field->points[4][1] = span3[0] * vec3[1] + center[1]; field->points[4][2] = span3[0] * vec3[2] + center[2]; field->points[5][0] = span3[1] * vec3[0] + center[0]; field->points[5][1] = span3[1] * vec3[1] + center[1]; field->points[5][2] = span3[1] * vec3[2] + center[2]; coordinate_3d_t corner[2]; Geo3d_Scalar_Field_Boundbox(field, corner); darray_print2(corner[0], 3, 1); darray_print2(corner[1], 3, 1); fprintf(fp, "%d %d %g %g %g %g %d\n", 1, 2, corner[0][0], corner[0][1], corner[0][2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 2, 2, corner[1][0], corner[0][1], corner[0][2], 3.0, 1); fprintf(fp, "%d %d %g %g %g %g %d\n", 3, 2, corner[1][0], corner[1][1], corner[0][2], 3.0, 2); fprintf(fp, "%d %d %g %g %g %g %d\n", 4, 2, corner[0][0], corner[1][1], corner[0][2], 3.0, 3); fprintf(fp, "%d %d %g %g %g %g %d\n", 5, 2, corner[0][0], corner[0][1], corner[0][2], 3.0, 4); fprintf(fp, "%d %d %g %g %g %g %d\n", 6, 2, corner[0][0], corner[0][1], corner[1][2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 7, 2, corner[1][0], corner[0][1], corner[1][2], 3.0, 6); fprintf(fp, "%d %d %g %g %g %g %d\n", 8, 2, corner[1][0], corner[1][1], corner[1][2], 3.0, 7); fprintf(fp, "%d %d %g %g %g %g %d\n", 9, 2, corner[0][0], corner[1][1], corner[1][2], 3.0, 8); fprintf(fp, "%d %d %g %g %g %g %d\n", 10, 2, corner[0][0], corner[0][1], corner[1][2], 3.0, 9); fprintf(fp, "%d %d %g %g %g %g %d\n", 11, 2, corner[0][0], corner[0][1], corner[1][2], 3.0, 1); fprintf(fp, "%d %d %g %g %g %g %d\n", 12, 2, corner[1][0], corner[0][1], corner[1][2], 3.0, 2); fprintf(fp, "%d %d %g %g %g %g %d\n", 13, 2, corner[1][0], corner[1][1], corner[1][2], 3.0, 3); fprintf(fp, "%d %d %g %g %g %g %d\n", 14, 2, corner[0][0], corner[1][1], corner[1][2], 3.0, 4); */ /* fprintf(fp, "%d %d %g %g %g %g %d\n", 5, 2, corner[1][0], corner[1][1], corner[1][2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 6, 2, corner[0][0], corner[1][1], corner[1][2], 3.0, 6); fprintf(fp, "%d %d %g %g %g %g %d\n", 7, 2, corner[1][0], corner[0][1], corner[1][2], 3.0, 7); fprintf(fp, "%d %d %g %g %g %g %d\n", 8, 2, corner[1][0], corner[1][1], corner[0][2], 3.0, 7); fprintf(fp, "%d %d %g %g %g %g %d\n", 12, 2, corner[1][0], corner[1][1], corner[0][2], 3.0, 2); fprintf(fp, "%d %d %g %g %g %g %d\n", 9, 2, corner[1][0], corner[1][1], corner[1][2], 3.0, 6); fprintf(fp, "%d %d %g %g %g %g %d\n", 10, 2, corner[0][0], corner[1][1], corner[1][2], 3.0, 3); fprintf(fp, "%d %d %g %g %g %g %d\n", 11, 2, corner[1][0], corner[0][1], corner[1][2], 3.0, 4); fprintf(fp, "%d %d %g %g %g %g %d\n", 12, 2, corner[1][0], corner[1][1], corner[0][2], 3.0, -1); */ fprintf(fp, "%d %d %g %g %g %g %d\n", 21, 2, span[0] * vec[0] + center[0], span[0] * vec[1] + center[1], span[0] * vec[2] + center[2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 22, 2, span[1] * vec[0] + center[0], span[1] * vec[1] + center[1], span[1] * vec[2] + center[2], 3.0, 21); fprintf(fp, "%d %d %g %g %g %g %d\n", 23, 2, span2[0] * vec2[0] + center[0], span2[0] * vec2[1] + center[1], span2[0] * vec2[2] + center[2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 24, 2, span2[1] * vec2[0] + center[0], span2[1] * vec2[1] + center[1], span2[1] * vec2[2] + center[2], 3.0, 23); fprintf(fp, "%d %d %g %g %g %g %d\n", 25, 2, span3[0] * vec3[0] + center[0], span3[0] * vec3[1] + center[1], span3[0] * vec3[2] + center[2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 26, 2, span3[1] * vec3[0] + center[0], span3[1] * vec3[1] + center[1], span3[1] * vec3[2] + center[2], 3.0, 25); fclose(fp); //double corner[6]; /* FILE *fp = fopen("../data/test.swc", "w"); fprintf(fp, "%d %d %g %g %g %g %d\n", 1, 2, span[0] * vec[0] + center[0], span[0] * vec[1] + center[1], span[0] * vec[2] + center[2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 2, 2, span[1] * vec[0] + center[0], span[1] * vec[1] + center[1], span[1] * vec[2] + center[2], 3.0, 1); fprintf(fp, "%d %d %g %g %g %g %d\n", 3, 2, span2[0] * vec2[0] + center[0], span2[0] * vec2[1] + center[1], span2[0] * vec2[2] + center[2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 4, 2, span2[1] * vec2[0] + center[0], span2[1] * vec2[1] + center[1], span2[1] * vec2[2] + center[2], 3.0, 3); fprintf(fp, "%d %d %g %g %g %g %d\n", 5, 2, span3[0] * vec3[0] + center[0], span3[0] * vec3[1] + center[1], span3[0] * vec3[2] + center[2], 3.0, -1); fprintf(fp, "%d %d %g %g %g %g %d\n", 6, 2, span3[1] * vec3[0] + center[0], span3[1] * vec3[1] + center[1], span3[1] * vec3[2] + center[2], 3.0, 5); fclose(fp); */ //calculate corners //Draw the six line of the corners /* Stack *stack2 = Copy_Stack(stack); Zero_Stack(stack2); int i = 0; for (i = 0; i < obj->size; i++) { stack2->array[Stack_Util_Offset(obj->voxels[i][0], obj->voxels[i][1], obj->voxels[i][2], stack->width, stack->height, stack->depth)] = 1; } Write_Stack("../data/test.tif", stack2); */ #endif #if 0 Stack *stack = Read_Stack("../data/test2.tif"); Stack_Threshold_Binarize(stack, 6); Objlabel_Workspace ow; STACK_OBJLABEL_OPEN_WORKSPACE(stack, (&ow)); ow.conn = 26; ow.init_chord = TRUE; int obj_size = Stack_Label_Largest_Object_W(stack, 1, 2, &ow); Object_3d *obj = Make_Object_3d(obj_size, ow.conn); extract_object(ow.chord, ow.seed, obj); //Print_Object_3d(obj); /* STACK_OBJLABEL_CLOSE_WORKSPACE((&ow)); Objlabel_Workspace *ow = New_Objlabel_Workspace(); ow->conn = 26; ow->init_chord = TRUE; STACK_OBJLABEL_OPEN_WORKSPACE(stack, ow); Stack_Label_Largest_Object_W(stack, 1, 2, ow); */ Write_Stack("../data/test3.tif", stack); #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("../data/test2.tif", -1); Print_Mc_Stack_Info(stack); size_t offset; size_t voxelNumber = Mc_Stack_Voxel_Number(stack); uint8_t* arrayc[3] = {NULL, NULL, NULL}; arrayc[0] = stack->array; arrayc[1] = stack->array + voxelNumber; arrayc[2] = stack->array + voxelNumber * 2; for (offset = 0; offset < voxelNumber; ++offset) { if ((arrayc[0][offset] != 128) || (arrayc[1][offset] != 6) || (arrayc[2][offset] != 0)) { arrayc[0][offset] = 0; arrayc[1][offset] = 0; arrayc[2][offset] = 0; } } Write_Mc_Stack("../data/test.tif", stack, NULL); Kill_Mc_Stack(stack); #endif #if 0 Mc_Stack *stack = Read_Mc_Stack("../data/flyem/TEM/slice_figure/segmentation/selected_body.tif", -1); Print_Mc_Stack_Info(stack); size_t offset; size_t voxelNumber = Mc_Stack_Voxel_Number(stack); Stack *mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); uint8_t* arrayc[4] = {NULL, NULL, NULL, NULL}; int i; for (i = 0; i < 4; ++i) { arrayc[i] = stack->array + voxelNumber * i; } for (offset = 0; offset < voxelNumber; ++offset) { if ((arrayc[0][offset] > 0) || (arrayc[1][offset] > 0) || (arrayc[2][offset] > 0) || (arrayc[3][offset] > 0)) { mask->array[offset] = 1; } else { mask->array[offset] = 0; } } mask = Downsample_Stack_Max(mask, 7, 7, 0, NULL); Write_Stack("../data/test.tif", mask); #endif #if 0 Stack *stack = Read_Stack("../data/test2.tif"); size_t offset; size_t voxelNumber = Stack_Voxel_Number(stack); color_t *arrayc = (color_t*) stack->array; for (offset = 0; offset < voxelNumber; ++offset) { if ((arrayc[offset][0] != 128) || (arrayc[offset][1] != 6) || (arrayc[offset][2] != 0)) { arrayc[offset][0] = 0; arrayc[offset][1] = 0; arrayc[offset][2] = 0; } } Write_Stack("../data/test.tif", stack); #endif #if 0 Stack *stack = Read_Stack("../data/flyem/TEM/slice_figure/segmentation/selected_body_volume.tif"); Stack *out = Make_Stack(COLOR, stack->width, stack->height, stack->depth); Zero_Stack(out); Object_3d_List *objs = Stack_Find_Object_N(stack, NULL, 255, 0, 26); Print_Object_3d_List_Compact(objs); uint8_t color[] = {0, 200, 50, 200, 0, 0}; uint8_t *color2 = color; while (objs != NULL) { Object_3d *obj = objs->data; Stack_Draw_Object_C(out, obj, color2[0], color2[1], color2[2]); color2 += 3; objs = objs->next; break; } Write_Stack("../data/test.tif", out); #endif #if 0 //Stack *stack = Read_Stack("../data/benchmark/binary/2d/btrig2.tif"); Stack *stack = Make_Stack(GREY, 3, 3, 3); One_Stack(stack); //Zero_Stack(stack); //Set_Stack_Pixel(stack, 0, 1, 1, 1, 1); Set_Stack_Pixel(stack, 0, 1, 1, 1, 0); Set_Stack_Pixel(stack, 0, 1, 1, 0, 0); Set_Stack_Pixel(stack, 0, 0, 0, 0, 0); Set_Stack_Pixel(stack, 0, 0, 2, 0, 0); Set_Stack_Pixel(stack, 0, 2, 0, 0, 0); Set_Stack_Pixel(stack, 0, 2, 2, 0, 0); Set_Stack_Pixel(stack, 0, 0, 0, 2, 0); Set_Stack_Pixel(stack, 0, 0, 2, 2, 0); Set_Stack_Pixel(stack, 0, 2, 0, 2, 0); Set_Stack_Pixel(stack, 0, 2, 2, 2, 0); //Set_Stack_Pixel(stack, 0, 1, 1, 2, 0); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); //Default_Stack_Graph_Workspace(sgw); sgw->signal_mask = stack; Graph *graph = Stack_Graph_W(stack, sgw); sgw->signal_mask = NULL; //Print_Graph(graph); //Graph_To_Dot_File(graph, "../data/test.dot"); if (Graph_Has_Hole(graph) == TRUE) { printf("The graph has a hole.\n"); } #endif #if 0 Stack *stack = Read_Stack("../data/flyem/skeletonization/session3/T1_207.tif"); size_t voxel_number = Stack_Voxel_Number(stack); size_t i; for (i = 0; i < voxel_number; ++i) { if (stack->array[i] == 1) { stack->array[i] = 255; } } Filter_3d *filter = Gaussian_Filter_3d(0.5, 0.5, 0.5); Stack *out = Filter_Stack(stack, filter); Write_Stack("../data/test2.tif", out); #endif #if 0 Stack *stack = Make_Stack(GREY, 3, 3, 3); Zero_Stack(stack); Cuboid_I cuboid; Cuboid_I_Set_S(&cuboid, 0, 0, 0, 4, 2, 3); Cuboid_I_Label_Stack(&cuboid, 1, stack); Print_Stack_Value(stack); #endif #if 0 Stack *stack = Make_Stack(GREY, 3, 3, 1); Zero_Stack(stack); Set_Stack_Pixel(stack, 1, 1, 0, 0, 1); Print_Stack_Value(stack); Stack *out = Downsample_Stack_Max(stack, 2, 2, 2, NULL); Print_Stack_Value(out); #endif #if 0 double t[3] = {1, 2 * 256 + 12, 255 * 256}; printf("%g\n", Stack_Voxel_Weight_C(t)); #endif #if 0 Stack *stack = Read_Stack_U("../data/vr/label.tif"); Stack_Binarize_Level(stack, 1); Stack_Label_Large_Objects_N(stack, NULL, 1, 2, 2000, 4); Stack_Threshold_Binarize(stack, 2); Write_Stack("../data/vr/label1.tif", stack); #endif #if 0 Stack *stack = Read_Stack_U("../data/vr/label.tif"); Stack_Binarize_Level(stack, 5); Stack_Label_Large_Objects_N(stack, NULL, 1, 2, 5000, 4); Stack_Threshold_Binarize(stack, 2); Write_Stack("../data/vr/label5.tif", stack); #endif #if 0 Stack *stack = Read_Stack_U("../data/vr/original.tif"); /* Make mask */ Stack *mask = Make_Stack(GREY, Stack_Width(stack), Stack_Height(stack), Stack_Depth(stack)); Zero_Stack(mask); Stack *overallLabel = Copy_Stack(mask); Stack *labelStack[5]; size_t voxelNumber = Stack_Voxel_Number(mask); size_t k; Struct_Element *se = Make_Disc_Se(5); int i; char filePath[100]; for (i = 0; i < 5; ++i) { sprintf(filePath, "../data/vr/label%d.tif", i + 1); labelStack[i] = Read_Stack_U(filePath); //labelStack[i] = Stack_Erode_Fast(labelStack[i], NULL, se); Stack_Or(mask, labelStack[i], mask); for (k = 0; k < voxelNumber; ++k) { if (labelStack[i]->array[k] == 1) { overallLabel->array[k] = i + 1; } } } for (k = 0; k < voxelNumber; ++k) { if (mask->array[k] == 1) { mask->array[k] = SP_GROW_SOURCE; } } Sp_Grow_Workspace *sgw = New_Sp_Grow_Workspace(); sgw->size = voxelNumber; Sp_Grow_Workspace_Set_Mask(sgw, mask->array); sgw->wf = Stack_Voxel_Weight_C; sgw->sp_option = 1; tic(); Int_Arraylist *path = Stack_Sp_Grow(stack, NULL, 0, NULL, 0, sgw); printf("time: %llu\n", toc()); Kill_Int_Arraylist(path); for (k = 0; k < voxelNumber; ++k) { if (mask->array[k] == 0) { int idx = (int) k; while (overallLabel->array[idx] == 0) { idx = sgw->path[idx]; } int label = overallLabel->array[idx]; idx = (int) k; while (overallLabel->array[idx] == 0) { overallLabel->array[idx] = label; idx = sgw->path[idx]; } } } for (k = 0; k < voxelNumber; ++k) { if (overallLabel->array[k] == 1 || overallLabel->array[k] == 5) { overallLabel->array[k] = 0; } } Write_Stack("../data/test.tif", overallLabel); Kill_Stack(stack); #endif return 0; }
int main(int argc, const char *argv[]) { const char *result_dir = "/Users/zhaot/Work/V3D/neurolabi/data/align"; const char *image_dir = "/Users/zhaot/Data/nathan/2008-04-18"; char file_path[150]; char image_path[150]; char result_path[150]; char file1[100], file2[100]; char id[100]; fullpath(result_dir, "align_input.txt", file_path); FILE *fp = fopen(file_path, "r"); while ((Read_Word(fp, file1, 0) > 0) && (Read_Word(fp, file2, 0) > 0)) { align_id(file1, file2, id); strcat(id, ".txt"); fullpath(result_dir, id, result_path); if (!fexist(result_path)) { printf("%s, %s\n", file1, file2); fullpath(image_dir, file1, image_path); Stack *stack1 = Read_Stack(image_path); fullpath(image_dir, file2, image_path); Stack *stack2 = Read_Stack(image_path); // Stack_Threshold_Tp4(stack1, 0, 65535); //Stack_Threshold_Tp4(stack2, 0, 65535); int chopoff1 = estimate_chopoff(stack1); printf("%d\n", chopoff1); Stack *substack1 = Crop_Stack(stack1, 0, 0, chopoff1, stack1->width, stack1->height, stack1->depth - chopoff1, NULL); int chopoff2 = estimate_chopoff(stack2); printf("%d\n", chopoff2); Stack *substack2 = Crop_Stack(stack2, 0, 0, chopoff2, stack2->width, stack2->height, stack2->depth - chopoff2, NULL); float unnorm_maxcorr; int offset[3]; int intv[] = {3, 3, 3}; float score = Align_Stack_MR_F(substack1, substack2, intv, 1, offset, &unnorm_maxcorr); if (score <= 0.0) { printf("failed\n"); write_align_result(result_dir, file1, file2, NULL); } else { offset[2] += chopoff2; printf("(%d, %d, %d): %g\n", offset[0], offset[1], offset[2], score); write_align_result(result_dir, file1, file2, offset); } Kill_Stack(substack1); Kill_Stack(substack2); Kill_Stack(stack1); Kill_Stack(stack2); } } fclose(fp); return 0; }
int main() { /* Read stack */ Stack *stack = Read_Stack("../data/fly_neuron.tif"); double z_scale = 1.0; /* New a bifold segment */ Local_Bifold_Neuroseg *locbn = New_Local_Bifold_Neuroseg(); /* Set_Local_Bifold_Neuroseg(locbn, 2, 2, 2, 2, 30, 0.5, TZ_PI_2, TZ_PI_2, -TZ_PI_2, 0, 461, 296, 144); //fly_neuron.tif */ Set_Local_Bifold_Neuroseg(locbn, 2, 2, 2, 2, 40, 0.5, TZ_PI_2, TZ_PI_2, TZ_PI_2, TZ_PI_2, 290, 304, 112); //fly_neuron.tif /* Set_Local_Bifold_Neuroseg(locbn, 2, 2, 2, 2, 30, 0.5, TZ_PI_2, TZ_PI_2, -TZ_PI_2, 0, 320, 164, 148); //fly_neuron.tif */ /* Set_Local_Bifold_Neuroseg(locbn, 3, 3, 3, 3, 30, 0.5, TZ_PI_2, TZ_PI_2, -TZ_PI_2, 0, 262, 136, 141); //fly_neuron2.tif */ /* Set_Local_Bifold_Neuroseg(locbn, 3, 3, 3, 3, 30, 0.5, TZ_PI_2, TZ_PI_2, -TZ_PI_2, 0, 236, 396, 143); //fly_neuron2.tif */ /* fit */ int var_index[LOCAL_BIFOLD_NEUROSEG_NPARAM]; int nvar = Local_Bifold_Neuroseg_Var_Mask_To_Index (BIFOLD_NEUROSEG_VAR_MASK_R | BIFOLD_NEUROSEG_VAR_MASK_KNOT | BIFOLD_NEUROSEG_VAR_MASK_ORIENTATION2 | BIFOLD_NEUROSEG_VAR_MASK_ORIENTATION, NEUROPOS_VAR_MASK_NONE, var_index); Fit_Local_Bifold_Neuroseg(locbn, stack, var_index, nvar, z_scale, NULL); Print_Local_Bifold_Neuroseg(locbn); /* Generate field */ Geo3d_Scalar_Field *field = Local_Bifold_Neuroseg_Field(locbn, 1.0, NULL); Delete_Local_Bifold_Neuroseg(locbn); /* Draw it in a stack */ Stack *label = Make_Stack(FLOAT32, stack->width, stack->height, stack->depth); Zero_Stack(label); double coef[] = {0.1, 255.0}; double range[] = {0.0, 10000.0}; Geo3d_Scalar_Field_Draw_Stack(field, label, coef, range); /* Turn the stack to GREY type */ Translate_Stack(label, GREY, 1); /* Make canvas */ Translate_Stack(stack, COLOR, 1); /* Label the canvas */ Stack_Label_Color(stack, label, 5.0, 1.0, label); /* Save the stack */ Write_Stack("../data/test.tif", stack); /* clean up */ Kill_Geo3d_Scalar_Field(field); Kill_Stack(stack); Kill_Stack(label); return 0; }