📄 cleantag.cc
字号:
TRUE, volume, (minc_input_options *) NULL ) ; if( status != OK ) exit(EXIT_FAILURE); if (verbose) printf ("Done\n");} /* load_volume(...) *//* ----------------------------- MNI Header -----------------------------------@NAME : scan_and_clean_tags@INPUT : @OUTPUT : @RETURNS : @DESCRIPTION: @METHOD : @GLOBALS : @CALLS : @CREATED : Nov. 4, 1995 (Vasco KOLLOKIAN)@MODIFIED : ---------------------------------------------------------------------------- */void scan_and_clean_tags( char *clean_mode ){ Real wx, wy, wz; /* world coordinates of tag */ Real v1, v2, v3; /* voxel ooordinates of tag */ int accept; /* flag to accept or reject a tag point */ int hi_idx; /* highest index to fuzzy_class */ int hi2_idx; /* second highest index to fuzzy_class */ Real *fuzzy_class; /* array to hold fuzzy values for classes */ Real hi_fuzzy; /* value of highest fuzzy class */ Real hi2_fuzzy; /* value of second highest fuzzy class */ Real mask_value; /* value of mask */ int lbl_idx; /* index to fuzzy_class corresponding to tag label */ int *reject_count; /* array to indicate number of rejected tags / class */ int *accept_count; /* array to indicate number of accepted tags / class */ Real mask_min = mask_binvalue - 0.5; Real mask_max = mask_binvalue + 0.5; /* reserve some memory for the fuzzy feature vector */ if (num_volumes) { ALLOC( fuzzy_class, num_volumes ); ALLOC( reject_count, num_volumes ); ALLOC( accept_count, num_volumes ); /* initialize reject_count, accept_count*/ for_less( fuzz_vol, 0, num_volumes ) { reject_count[fuzz_vol] = 0; accept_count[fuzz_vol] = 0; } } if (debug > 1) fprintf(stdout, "Starting tag point loop, %d tag points\n", num_oldtags); /* repeat for each tag point */ for_less( tagpoint, 0, num_oldtags) { /* initialize values */ accept = TRUE; hi_idx = 0; hi2_idx = 0; hi_fuzzy = 0; hi2_fuzzy = 0; lbl_idx = 0; /* get the world coordinate of tag point */ wx = tags[tagpoint][X]; wy = tags[tagpoint][Y]; wz = tags[tagpoint][Z]; /* convert tag world to voxel */ /* use first volume or mask */ convert_3D_world_to_voxel(num_volumes ? in_volume[0] : mask_volume, wx, wy, wz, &v1, &v2, &v3); /* if a mask is specified, check whether the tag point is in the mask */ if (mask_filename) { mask_value = get_volume_real_value( mask_volume, ROUND(v1), ROUND(v2), ROUND(v3), 0, 0); if ((mask_value < mask_min) || (mask_value > mask_max)) { accept = FALSE; goto copy_tag; } } /* check to see if the tag point is in the volume before fetching the image value at that position - if not, then reject the point */ if ( !voxel_is_in_volume( v1, v2, v3 ) ) { accept = FALSE; goto copy_tag; } if (!num_volumes) goto copy_tag; /* load fuzzy labels of the voxel into the fuzzy class vector */ for_less( fuzz_vol, 0, num_volumes ) fuzzy_class[fuzz_vol] = get_volume_real_value( in_volume[fuzz_vol], (int)v1, (int)v2, (int)v3, 0, 0); /* find the highest fuzzy index in the fuzzy_class[] array */ for_less( fuzz_vol, 0, num_volumes ) { if ( hi_fuzzy < fuzzy_class[fuzz_vol] ) { hi_fuzzy = fuzzy_class[fuzz_vol]; hi_idx = fuzz_vol; } } /* find the second highest fuzzy index in the fuzzy_class[] array */ for_less( fuzz_vol, 0, num_volumes ) { if ( hi2_fuzzy < fuzzy_class[fuzz_vol] ) { if ( fuzz_vol != hi_idx ) { hi2_fuzzy = fuzzy_class[fuzz_vol]; hi2_idx = fuzz_vol; } } } /* for_less */ /* find the fuzzy_label index which corresponds to tag label */ for_less( fuzz_vol, 0, num_volumes ) { if ( !strcmp (fuzzy_label[fuzz_vol], labels[tagpoint]) ) { lbl_idx = fuzz_vol; break; } } /* for_less */ /* now start testing for the 'clean_mode string' */ /* test for case of x = 1 */ if ( clean_mode[0] == '1' ) { /* if tag label != highest class label, reject tag */ if ( strcmp( labels[tagpoint], fuzzy_label[hi_idx] ) ) { accept = FALSE; goto copy_tag; } } /* test for case of y = 1 */ if ( clean_mode[1] == '1' ) { if ( fuzzy_class[lbl_idx] < threshold ) { accept = FALSE; goto copy_tag; } } /* test for case of z = 1 */ if ( clean_mode[2] == '1' ) { if ( ( fuzzy_class[hi_idx] - fuzzy_class[hi2_idx] ) < diff_thresh ) { accept = FALSE; goto copy_tag; } } copy_tag: if ( accept ) { /* copy world coordinates */ SET_ARRAY_SIZE( new_tags, new_tagpoint, new_tagpoint+1, 1000); ALLOC( new_tags[new_tagpoint], 3); new_tags[new_tagpoint][X] = wx; new_tags[new_tagpoint][Y] = wy; new_tags[new_tagpoint][Z] = wz; /* copy label */ SET_ARRAY_SIZE( new_labels, new_tagpoint, new_tagpoint+1, 1000); ALLOC( new_labels[new_tagpoint], sizeof( labels[tagpoint] ) + 1); strcpy(new_labels[new_tagpoint], labels[tagpoint]); new_tagpoint++; if ( debug >= 4 ) { fprintf( stdout, "accepting tag %f %f %f -> %s\n", wx, wy, wz, labels[tagpoint] ); } if (num_volumes) accept_count[lbl_idx]++; } /* if ( copy_tag ) */ else { if ( debug >= 3 ) { fprintf( stdout, "rejecting tag %f %f %f -> %s\n", wx, wy, wz, labels[tagpoint] ); } if (num_volumes) reject_count[lbl_idx]++; } } /* for_less ( tagpoint...) */ if ( verbose & num_volumes ) for_less( fuzz_vol, 0, num_volumes ) fprintf(stdout, "Rejected %d, accepted %d, class %s\n", reject_count[fuzz_vol], accept_count[fuzz_vol], fuzzy_label[fuzz_vol]); } /* scan_and_clean_tags(...) */ /* ----------------------------- MNI Header -----------------------------------@NAME : write_tag_file@INPUT : @OUTPUT : @RETURNS : @DESCRIPTION: @METHOD : @GLOBALS : @CALLS : @CREATED : Mar. 1, 1995 (Vasco KOLLOKIAN)@MODIFIED : ---------------------------------------------------------------------------- */void write_tag_file(void){ if (verbose) printf("Writing tag file %s ...\n", new_tag_filename); if (output_tag_file(new_tag_filename, comment, 1, new_tagpoint, new_tags, NULL, NULL, NULL, NULL, new_labels) != OK) exit(EXIT_FAILURE); } /* ----------------------------- MNI Header -----------------------------------@NAME : load_tag_file@INPUT : name of tag file@OUTPUT : @RETURNS : number of tag points read@DESCRIPTION: opens and loads a tag file@METHOD : @GLOBALS : @CALLS : @CREATED : May 29, 1995 ( Vasco KOLLOKIAN)@MODIFIED : Oct 22, 1995 ( Vasco KOLLOKIAN)---------------------------------------------------------------------------- */void load_tag_file ( char *tag_filename ){ int num_vol, k; if (verbose) (void) fprintf(stdout, "Loading tagfile %s\n", tag_filename); /* read the tag file */ if ( input_tag_file(tag_filename, &num_vol, &num_oldtags, &tags, NULL, NULL, NULL, NULL, &labels ) != OK ) { fprintf(stderr, "Error reading the tag file.\n"); exit(EXIT_FAILURE); }} /* load_tag_file (...) *//* ----------------------------- MNI Header -----------------------------------@NAME : voxel_is_in_volume@INPUT : @OUTPUT : @RETURNS : @DESCRIPTION: check to see if a voxel is in the volume (vol 0 is same as all)@METHOD : @GLOBALS : @CALLS : @CREATED : Sep 22, 1995 ( Vasco KOLLOKIAN)@MODIFIED : Mar 5, 1996 ( Vasco KOLLOKIAN)---------------------------------------------------------------------------- */int voxel_is_in_volume( Real vox1, Real vox2, Real vox3 ){ /* in_volume[0] is the volume against which the tags are verified */ if ( vox1 < -0.5 || vox1 >= (Real) volume_sizes[0] - 0.5) return FALSE; else if ( vox2 < -0.5 || vox2 >= (Real) volume_sizes[1] - 0.5) return FALSE; else if ( vox3 < -0.5 || vox3 >= (Real) volume_sizes[2] - 0.5) return FALSE; else return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -