📄 classify.cc
字号:
exit(EXIT_FAILURE); } /* if a mask is specified, make sure it exists */ if (mask_filename && !file_exists(mask_filename)) { (void) fprintf(stderr,"File `%s' doesn't exists ! \n", mask_filename); exit(EXIT_FAILURE); } if ( train_only && save_train_filename == NULL ) { (void) fprintf(stderr,"-train_only : please specify -save_train <file>\n"); exit(EXIT_FAILURE); } if ( train_only && fuzzy ) { (void) fprintf(stderr,"-train_only and -fuzzy are mutually exclusive.\n"); exit(EXIT_FAILURE); } if ( dump_features && fuzzy ) { (void) fprintf(stderr,"-dump_features and -fuzzy are mutually exclusive.\n"); exit(EXIT_FAILURE); } /* for load_train_filename, checking perhaps should be done by the actual routine that is doing the loading, in that case it could take default values in case a filename is not provided */ if ( load_train_filename && !file_exists(load_train_filename) ) { (void) fprintf(stderr,"File `%s' doesn't exist !\n ", load_train_filename); exit(EXIT_FAILURE); } if (!clobber_training && save_train_filename && file_exists(save_train_filename)) { (void) fprintf(stderr,"File `%s' exists !\n", save_train_filename); (void) fprintf(stderr,"Use -clob_tr to overwrite output training file.\n"); exit(EXIT_FAILURE); } if (!tagfile_filename && !load_train_filename && !tagvolume_buffer && (argc > 2 ) ) { /* argc > 2 is used to supress the message only if -help is used */ (void) fprintf(stderr,"Specify one of -tagfile or -load_train.\n"); exit(EXIT_FAILURE); } if ( apriori && !tagvolume_buffer ) { (void) fprintf(stderr,"Specify apriori volumes with -volume\n"); exit(EXIT_FAILURE); } /* make sure the specified tag file exists */ if (tagfile_filename != NULL && !file_exists(tagfile_filename) ) { (void) fprintf(stderr,"File `%s' doesn't exist !\n ", tagfile_filename); exit(EXIT_FAILURE); } if (tagfile_filename != NULL && load_train_filename != NULL ) { (void) fprintf(stderr,"-tagfile, -load_train are mutually exlusive.\n"); exit(EXIT_FAILURE); } /* parse the argument supplied by the -volume switch, which is a comma separated collection of training volume filenames, num_train_vols is determined by the number of training volumes supplied, */ if ( tagvolume_buffer) { if ( debug > 4 ) fprintf( stdout, "tagvolume_buffer = %s\n", tagvolume_buffer); while ( 1 ) { /* while buf is not a ',' or null, advance pointer and copy character */ while ( tagvolume_buffer[src_idx] != ',' && tagvolume_buffer[src_idx] != '\0') { fuzzy_train_buffer[buff_idx][dst_idx++] = tagvolume_buffer[src_idx++]; } /* as soon as you encounter a ',' or null, end target string */ fuzzy_train_buffer[buff_idx][dst_idx] = '\0'; /* reset target string pointer */ dst_idx = 0; /* advance to next storage slot */ buff_idx++; /* increment the number of training volumes */ num_train_vols++; /* if you reach the end of the string, break and carry on */ if (tagvolume_buffer[src_idx] == '\0') break; else src_idx++; } /* allocate space for the filename array */ ALLOC( trainvol_filename, num_train_vols); /* allocate space, and copy buffer content */ for_less( i, 0, num_train_vols ) { ALLOC( trainvol_filename[i], strlen(fuzzy_train_buffer[i])+1 ); strcpy( trainvol_filename[i], fuzzy_train_buffer[i] ); if ( debug > 4 ) fprintf( stdout, "%s\n", trainvol_filename[i]); if ( !file_exists(trainvol_filename[i]) ) { fprintf(stderr,"File `%s' doesn't exist !\n ", trainvol_filename[i]); exit(EXIT_FAILURE); } } /* allocate memory for training volume pointers */ ALLOC( train_volume, num_train_vols); } /* if ( trainvol_buffer ) */} /* parse_arguments *//* ----------------------------- MNI Header -----------------------------------@NAME : allocate_memory@INPUT : @OUTPUT : @RETURNS : @DESCRIPTION: allocates some memory for data structures@METHOD : @GLOBALS : @CALLS : @CREATED : June 10, 1995 (Vasco KOLLOKIAN)@MODIFIED : ---------------------------------------------------------------------------- */void allocate_memory(void) { /* allocate some memory for feature vector */ ALLOC(feature_vector, num_features); /* allocate memory for first volume sizes */ ALLOC(first_volume_sizes, MAX_DIMENSIONS); /* allocate memory for volume pointers */ ALLOC( in_volume, num_features); }/* ----------------------------- MNI Header -----------------------------------@NAME : load_input_volumes@INPUT : @OUTPUT : @RETURNS : @DESCRIPTION: @METHOD : @GLOBALS : in_volume[j] - the number of input volumes@CALLS : @CREATED : @MODIFIED : Feb 10, 1996 ( Vasco KOLLOKIAN) ---------------------------------------------------------------------------- */void load_input_volumes(void){ int j; /* read the volumes in one by one */ for_less( j, 0, num_features ) { if (verbose) fprintf (stdout, "Loading volume %s\n", input_filename[j]); /* load the volume */ status = input_volume(input_filename[j], 3, NULL, /* File_order_dimension_names, */ type, sign, 0.0, 0.0, TRUE, &in_volume[j], (minc_input_options *) NULL ) ; if ( status != OK ) exit(EXIT_FAILURE); /* if loading the very first volume, get its sizes, number of dims and dim names, dim starts and dim steps */ if ( j == 0 ) { int k; /* local counter */ get_volume_sizes(in_volume[0], first_volume_sizes); first_volume_num_dims = get_volume_n_dimensions(in_volume[0]); first_volume_dim_names = get_volume_dimension_names(in_volume[0]); if ( debug > 2 ) { fprintf(stdout, "Vol number of dims. = %d\n", first_volume_num_dims); fprintf(stdout, "Vol dimension names = "); for_less ( k, 0, first_volume_num_dims ) fprintf(stdout, "%s ", first_volume_dim_names[k]); fprintf(stdout, "\n"); } } /* if you have more than one volume, check to see if volumes are of same size in each dim and make sure the dimension orders are also the same. this is done by volume_size_is_ok() function */ if ( j >= 1 && !volume_size_is_ok( in_volume[j] )){ (void) fprintf(stderr,"in volume %s\n", input_filename[j]); exit(EXIT_FAILURE); } } /* for_less j */ } /* load_input_volumes */ /* ----------------------------- MNI Header -----------------------------------@NAME : load_mask_volume@INPUT : @OUTPUT : @RETURNS : @DESCRIPTION: loads the mask in form of minc file@METHOD : @GLOBALS : @CALLS : @CREATED : Sep. 15, 1995 (Vasco KOLLOKIAN)@MODIFIED : ---------------------------------------------------------------------------- */void load_mask_volume(char *mask_file){ if (verbose) fprintf (stdout, "Loading mask volume %s\n", mask_file); /* load the volume */ status = input_volume(mask_file, 3, NULL, /* File_order_dimension_names, */ type, sign, 0.0, 0.0, TRUE, &mask_volume, (minc_input_options *) NULL ) ; if ( status != OK ) exit(EXIT_FAILURE); if ( !volume_size_is_ok( mask_volume) ) { fprintf( stderr, "in mask volume %s\n", mask_file); exit(EXIT_FAILURE); } } /* load_mask_volume */ /* ----------------------------- MNI Header -----------------------------------@NAME : create_empty_classified_volume@INPUT : @OUTPUT : @RETURNS : @DESCRIN: cre and initialized an empty classified volume@METHOD : @GLOBAL : cssified_volume@CALLS : @CREATED : February 6, 1995 (Vasco KOLLOKIAN)@MODIFIED : -------------------------------------------------------------------------- */void create_empty_classified_volume(void){ Real minval = (output_range[0] == -MAXDOUBLE) ? 0 : output_range[0]; Real maxval = (output_range[1] == -MAXDOUBLE) ? max_class_index : output_range[1]; /* create the classification volume here */ if (verbose) { write(2,"Creating output volume\n",23); } classified_volume = copy_volume_definition(in_volume[0], NC_BYTE, FALSE, minval, maxval); set_volume_voxel_range(classified_volume, minval, maxval); set_volume_real_range(classified_volume, minval, maxval); if ( cache_set ) { set_cache_output_volume_parameters(classified_volume, output_filename, NC_BYTE, FALSE, minval, maxval, input_filename[0], history, (minc_output_options *) NULL ) ; }} /* create_empty_classified_volume *//* ----------------------------- 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 : ---------------------------------------------------------------------------- */void load_tag_file ( char *tag_filename ){ if (verbose) (void) fprintf(stdout, "Loading tagfile %s\n", tagfile_filename); /* tag file should be opened here */ if ( input_tag_file(tag_filename, &n_tag_volumes, &num_samples, &tags, NULL, NULL, NULL, NULL, &labels ) != OK ) { printf("Error reading the tag file.\n"); exit(EXIT_FAILURE); } if ( n_tag_volumes == 2 ) printf("Tag file contains two volumes, using the first one.\n");}/* ----------------------------- MNI Header -----------------------------------@NAME : load_train_volumes@INPUT : @OUTPUT : @RETURNS : @DESCRIPTION: @METHOD : @GLOBALS : @CALLS : @CREATED : @MODIFIED : Feb 11, 1996 ( Vasco KOLLOKIAN )---------------------------------------------------------------------------- */void load_train_volumes(char **trainvol_filename){ int i; /* load the training volumes */ for_less( i, 0, num_train_vols ) { if (verbose) fprintf (stdout, "Loading tag volume %s\n", trainvol_filename[i]); status = input_volume(trainvol_filename[i], 3, NULL, /* File_order_dimension_names, */ NC_BYTE, FALSE, 0.0, 0.0, TRUE, &train_volume[i], (minc_input_options *) NULL ) ; if ( status != OK ) exit(EXIT_FAILURE); if ( !volume_size_is_ok( train_volume[i] ) ) { fprintf( stderr, "in training volume %s\n", trainvol_filename); exit(EXIT_FAILURE); } } /* for_less( i, 0, num_train_vols ) */ } /* load_train_volume */ /* ----------------------------- MNI Header -----------------------------------@NAME : void create_feature_matrix_from_tagfile@INPUT : @OUTPUT : @RETURNS : create a feature matrix and a class vector for each point@DESCRIPTION: @METHOD : @GLOBALS : @CALLS : @CREATED : May 29, 1995 (Vasco KOLLOKIAN)@MODIFIED : ---------------------------------------------------------------------------- */void create_feature_matrix_from_tagfile(void) { int i, j; /* counters i, over samples, j over volumes */ Real wx, wy, wz; /* world x y z coordinates */ Real v1, v2, v3; /* voxel x y z coordinates */ Real value; /* voxel value to go into feature matrix */ int num_adj_samples; /* var to hold the number of adjusted samples */ Real *class_counter; /* int array to count the number of classes in samples */ /* set adjusted samples to zero, it will also index into feature_matrix and class column.*/ num_adj_samples = 0; if (verbose) (void) fprintf(stdout, "Creating feature matrix from tagfile\n"); /* allocate memory for feature matrix space, as big as your samples size */ ALLOC2D( feature_matrix, num_samples, num_features); /* allocate momory for the class column, also as big as your samples size*/ ALLOC( class_column, num_samples );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -