⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cleantag.cc

📁 KNN algorithm, and related
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* ----------------------------- MNI Header -----------------------------------@NAME       : cleantag@INPUT      : @OUTPUT     : @RETURNS    : @DESCRIPTION: @METHOD     : @GLOBALS    : @CALLS      : @CREATED    : Nov 4, 1995 (Vasco KOLLOKIAN)@MODIFIED   : ---------------------------------------------------------------------------- */#include "config.h"extern "C" {#include <volume_io.h>}#include <ParseArgv.h>/* function prototypes */void parse_arguments(int argc, char* argv[]);void load_volume(char *, Volume * );void load_tag_file( char *);void scan_and_clean_tags( char *clean_mode );void write_tag_file(void);int voxel_is_in_volume( Real vox1, Real vox2, Real vox3 );/* global variables */Status     status;int        verbose = FALSE;int        clobber = FALSE;int        debug = 0;Real       threshold = 0.9;      /* denote fuzzy acceptance level */Real       diff_thresh = 0.1;    /* denote fuzzy proximity rejection level */char       *tag_filename;                /* original tag filename */char       *new_tag_filename;            /* cleaned tag filename */char       *mask_filename = NULL;        /* mask volume */int        mask_binvalue = 1;            /* value of mask foreground */char       *comment;                     /* comment string */char       *clean_mode = NULL;           /* string to denote cleaning mode*/char       **fuzzy_label;char       **input_filename;Volume     *in_volume;int        num_volumes;Volume     mask_volume;int        *volume_sizes;Real       **tags;char       **labels;long       tagpoint;Real       **new_tags;char       **new_labels;int        new_tagpoint = 0;int        num_oldtags = 0;int        fuzz_vol;                    /* index to  number of fuzzy volumes */int        block_sizes[3] = { 1, 1, 1}; /* set the block size for vol. cache */ArgvInfo argTable[] = {  { NULL, ARGV_VERINFO, VERSION, NULL, NULL },  {"-verbose", ARGV_CONSTANT, (char *) TRUE, (char *) &verbose,     "Show progress"},    {"-clobber", ARGV_CONSTANT, (char *) TRUE, (char *) &clobber,     "Overwrite output file."},    {"-debug", ARGV_INT, (char *) NULL, (char *) &debug,     "Show debugging information"},    {"-oldtag", ARGV_STRING, (char *) NULL, (char *) &tag_filename,     "Specify the tag file to be cleaned"},        {"-newtag", ARGV_STRING, (char *) NULL, (char *) &new_tag_filename,     "Specify the file name of the clean set of tag points"},           {"-mask", ARGV_STRING, (char *) NULL, (char *) &mask_filename,     "Specify a mask to apply to the tag points"},           {"-maskbinvalue", ARGV_INT, (char *) NULL, (char *) &mask_binvalue,     "Value of mask foreground"},  {"-mode", ARGV_STRING, (char *) NULL, (char *) &clean_mode,      "Specify a quoted string 'xyz' to denote tag rejection mode.\n \      Each of x,y,z being 0 or 1,  effects are additive.\n \      x = 1, if tag class label <> voxel class (highest fuzzy voxel class),\n \      y = 1, if fuzzy voxel class < threshold,\n \      z = 1, if diff. between 2 highest fuzzy voxel classes < diff. threshold,\n"},  {"-threshold", ARGV_FLOAT, (char *) 1, (char *) &threshold,     "Set the fuzzy threshold rejection criterion (applies to 'y' under -mode)"},  {"-difference", ARGV_FLOAT, (char *) NULL, (char *) &diff_thresh,     "Set the difference threshold rejection criterion (applies to 'z' under -mode)"},  {"-comment", ARGV_STRING, (char *) NULL, (char *) &comment,      "Specify a comment to be included in the cleaned tag file."},  {NULL, ARGV_END, NULL, NULL, NULL}};int main(int argc, char *argv[]){  parse_arguments(argc, argv);  /* set volume caching options to random */  set_n_bytes_cache_threshold(0);  set_default_max_bytes_in_cache(0);  set_default_cache_block_sizes(block_sizes);   /* optimized for tag access */  load_tag_file(tag_filename);  ALLOC(volume_sizes, MAX_DIMENSIONS);  if (mask_filename)    load_volume( mask_filename, &mask_volume );  if (num_volumes) {    /* allocate memory for vol. pointer and start loading the volumes */    ALLOC( in_volume, num_volumes );    for_less ( fuzz_vol, 0, num_volumes )       load_volume( input_filename[fuzz_vol], &in_volume[fuzz_vol] );    get_volume_sizes(in_volume[0], volume_sizes);  }  else    get_volume_sizes(mask_volume, volume_sizes);  /* for each volume loaded, scan the the tag file and clean */  scan_and_clean_tags( clean_mode );  /* write the newly created tags to a file */  write_tag_file();  if (num_volumes)    for_less (fuzz_vol, 0, num_volumes)       delete_volume(in_volume[fuzz_vol]);  if (mask_filename)    delete_volume(mask_volume);  return (EXIT_SUCCESS);} /* main *//* ----------------------------- MNI Header -----------------------------------@NAME       : parse_arguments@INPUT      : @OUTPUT     : @RETURNS    : @DESCRIPTION: @METHOD     : @GLOBALS    : @CALLS      : @CREATED    : Feb. 28, 1995 (Vasco KOLLOKIAN)@MODIFIED   : ---------------------------------------------------------------------------- */void parse_arguments(int argc, char* argv[]){  int k;      /* volume filename index */  int m = 2;  /* used to offset class argument */  /* Call ParseArgv */  if ( ParseArgv(&argc, argv, argTable, 0) ) {    (void) fprintf(stderr, 		   "\nUsage: %s [options] <fuzzy_class.mnc> <class_id> [<fuzzy_class.mnc> <class_id> ...]\n", 		   argv[0]);    (void) fprintf(stderr,   		   "       %s [-help]\n\n", argv[0]);    exit(EXIT_FAILURE);  }  if ( debug > 1) {    fprintf(stdout, "the number of arguments left = %d\n", argc);    for ( k = 0; k < argc; k++)      fprintf(stdout, "argv[%d] = %s\n", k, argv[k]);  }  /* make sure you specify a new tag filename */  if (!new_tag_filename) {    printf("Please specify a new tag filename with -newtag switch\n");    exit(EXIT_FAILURE);  }    /* make sure you specify a old tag filename */  if (!file_exists(tag_filename)) {        printf("Tag file %s does not exist.\n", tag_filename);    exit(EXIT_FAILURE);  }    /* warn of clobbering if new tag file exists */  if (new_tag_filename && !clobber && file_exists(new_tag_filename)) {        printf("File %s exists.\n", new_tag_filename);    printf("Use -clobber to overwrite.\n");    exit(EXIT_FAILURE);  }  if ( !clean_mode && !mask_filename ) {    fprintf( stdout, "Please specify -mode and/or -mask\n");    exit(EXIT_FAILURE);  }  if (clean_mode) {    /* make sure that clean_mode is only 3 characters long */    if ( strlen( clean_mode ) != 3 )  {            fprintf( stdout, "Cleaning mode should be 3 characters long. ex '011' \n");      exit(EXIT_FAILURE);    }        for_less( k, 0, 3 ) {      if ( debug >= 1 ) 	fprintf( stdout, "clean_mode[%d] = %c\n", k, clean_mode[k]);            if ( clean_mode[k] != '0' && clean_mode[k] != '1' ) {		fprintf( stdout, "Invalid cleaning mode, please user 0 or 1.\n");	exit(EXIT_FAILURE);      }    }  }  /* Check mask, if specified */  if (mask_filename) {    if (!file_exists(mask_filename)) {      printf("Mask file %s does not exist.\n", mask_filename);      exit(EXIT_FAILURE);    }  }    /* make sure each volume has a class label */  if ( ( argc - 1) % 2 != 0 ) {    fprintf(stderr, "Please specify a class label.\n");       exit(EXIT_FAILURE);   }       num_volumes = ( argc - 1 ) / 2;  /* count out progname */   if ( debug > 1 )     fprintf(stdout, "the number of volumes = %d\n", num_volumes);   if ( threshold <= 0 ) {        fprintf(stdout, "Please choose a positive threshold\n");    exit(EXIT_FAILURE);  }    if (num_volumes) {    ALLOC( input_filename, num_volumes );        ALLOC( fuzzy_label, num_volumes );        for_less ( k, 0, num_volumes) {            if (!file_exists(argv[(k*m)+1])) {		(void) fprintf(stderr, "filename `%s' not found. \n", argv[(k*m)+1]);	exit(EXIT_FAILURE);      }            /* get the filename and class label */      input_filename[k] = argv[(k*m)+1];            fuzzy_label[k] = argv[(k*m)+2];            if ( debug > 1 ) {		fprintf( stdout, "input_filename[%d] = %s\n", k, input_filename[k]);	fprintf( stdout, "fuzzy_label[%d] = %s\n", k, fuzzy_label[k]);      }          } /* for_less ( k...) */  }} /* parse_arguments() *//* ----------------------------- MNI Header -----------------------------------@NAME       : load_volume@INPUT      : @OUTPUT     : @RETURNS    : @DESCRIPTION: @METHOD     : @GLOBALS    : @CALLS      : @CREATED    : Feb. 28, 1995 (Vasco KOLLOKIAN)@MODIFIED   : ---------------------------------------------------------------------------- */void load_volume(char *in_filename, Volume *volume){  if (verbose)    printf ("Processing volume %s...", in_filename);    /* load the volume */  status = input_volume( in_filename, 3, NULL, NC_UNSPECIFIED, 			 FALSE, 0.0, 0.0,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -