Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
3dRowFillin.c
Go to the documentation of this file.00001 #include "mrilib.h"
00002
00003 int main( int argc , char * argv[] )
00004 {
00005 int iarg=1 , dcode=0 , maxgap=9 , nftot=0 ;
00006 char * prefix="rowfillin" , * dstr=NULL;
00007 THD_3dim_dataset * inset , * outset ;
00008 MRI_IMAGE * brim ;
00009 int verb=0 ;
00010
00011 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00012 printf("Usage: 3dRowFillin [options] dataset\n"
00013 "Extracts 1D rows in the given direction from a 3D dataset,\n"
00014 "searches for blank (zero) regions, and fills them in if\n"
00015 "the blank region isn't too large and it is flanked by\n"
00016 "the same value on either edge. For example:\n"
00017 " input row = 0 1 2 0 0 2 3 0 3 0 0 4 0\n"
00018 " output row = 0 1 2 2 2 2 3 3 3 0 0 4 0\n"
00019 "\n"
00020 "OPTIONS:\n"
00021 " -maxgap N = set the maximum length of a blank region that\n"
00022 " will be filled in to 'N' [default=9].\n"
00023 " -dir D = set the direction of fill to 'D', which can\n"
00024 " be one of the following:\n"
00025 " A-P, P-A, I-S, S-I, L-R, R-L, x, y, z\n"
00026 " The first 6 are anatomical directions;\n"
00027 " the last 3 are reference to the dataset\n"
00028 " internal axes [no default value].\n"
00029 " -prefix P = set the prefix to 'P' for the output dataset.\n"
00030 "\n"
00031 "N.B.: If the input dataset has more than one sub-brick,\n"
00032 " only the first one will be processed.\n"
00033 "\n"
00034 "The intention of this program is to let you fill in slice gaps\n"
00035 "made when drawing ROIs with the 'Draw Dataset' plugin. If you\n"
00036 "draw every 5th coronal slice, say, then you could fill in using\n"
00037 " 3dRowFillin -maxgap 4 -dir A-P -prefix fredfill fred+orig\n"
00038 "\n"
00039 ) ;
00040 exit(0) ;
00041 }
00042
00043 mainENTRY("3dRowFillin main"); machdep(); AFNI_logger("3dRowFillin",argc,argv);
00044 PRINT_VERSION("3dRowFillin") ;
00045
00046
00047
00048 while( iarg < argc && argv[iarg][0] == '-' ){
00049
00050 if( strncmp(argv[iarg],"-verb",5) == 0 ){
00051 verb++ ; iarg++ ; continue ;
00052 }
00053
00054 if( strcmp(argv[iarg],"-prefix") == 0 ){
00055 prefix = argv[++iarg] ;
00056 if( !THD_filename_ok(prefix) ){
00057 fprintf(stderr,"*** Illegal string after -prefix!\n"); exit(1) ;
00058 }
00059 iarg++ ; continue ;
00060 }
00061
00062 if( strcmp(argv[iarg],"-maxgap") == 0 ){
00063 maxgap = strtol( argv[++iarg] , NULL , 10 ) ;
00064 if( maxgap < 1 ){
00065 fprintf(stderr,"*** Illegal value after -maxgap!\n"); exit(1);
00066 }
00067 iarg++ ; continue ;
00068 }
00069
00070 if( strcmp(argv[iarg],"-dir") == 0 ){
00071 dstr = argv[++iarg] ;
00072 iarg++ ; continue ;
00073 }
00074
00075 fprintf(stderr,"*** Illegal option: %s\n",argv[iarg]) ; exit(1) ;
00076 }
00077
00078 if( dstr == NULL ){
00079 fprintf(stderr,"*** No -dir option on command line!\n"); exit(1);
00080 }
00081 if( iarg >= argc ){
00082 fprintf(stderr,"*** No input dataset on command line!\n"); exit(1);
00083 }
00084
00085 inset = THD_open_dataset( argv[iarg] ) ;
00086 if( inset == NULL ){
00087 fprintf(stderr,"*** Can't open dataset %s\n",argv[iarg]); exit(1);
00088 }
00089
00090 outset = EDIT_empty_copy( inset ) ;
00091 EDIT_dset_items( outset , ADN_prefix , prefix , ADN_none ) ;
00092 if( THD_is_file( DSET_HEADNAME(outset) ) ){
00093 fprintf(stderr,"** Output file %s exists -- cannot overwrite!\n",
00094 DSET_HEADNAME(outset) ) ;
00095 exit(1) ;
00096 }
00097
00098 tross_Copy_History( inset , outset ) ;
00099 tross_Make_History( "3dRowFillin" , argc,argv , outset ) ;
00100
00101 if( DSET_NVALS(inset) > 1 ){
00102 fprintf(stderr,"++ WARNING: input dataset has more than one sub-brick!\n");
00103 EDIT_dset_items( outset ,
00104 ADN_ntt , 0 ,
00105 ADN_nvals , 1 ,
00106 ADN_none ) ;
00107 }
00108
00109 if( DSET_BRICK_TYPE(outset,0) != MRI_short &&
00110 DSET_BRICK_TYPE(outset,0) != MRI_byte ){
00111
00112 fprintf(stderr,"*** This program only works on byte and short dataset!\n");
00113 exit(1) ;
00114 }
00115
00116 switch( *dstr ){
00117 case 'x': dcode = 1 ; break ;
00118 case 'y': dcode = 2 ; break ;
00119 case 'z': dcode = 3 ; break ;
00120
00121 default:
00122 if( *dstr == ORIENT_tinystr[outset->daxes->xxorient][0] ||
00123 *dstr == ORIENT_tinystr[outset->daxes->xxorient][1] ) dcode = 1 ;
00124
00125 if( *dstr == ORIENT_tinystr[outset->daxes->yyorient][0] ||
00126 *dstr == ORIENT_tinystr[outset->daxes->yyorient][1] ) dcode = 2 ;
00127
00128 if( *dstr == ORIENT_tinystr[outset->daxes->zzorient][0] ||
00129 *dstr == ORIENT_tinystr[outset->daxes->zzorient][1] ) dcode = 3 ;
00130 break ;
00131 }
00132 if( dcode == 0 ){
00133 fprintf(stderr,"*** Illegal -dir direction!\n") ; exit(1) ;
00134 }
00135 if( verb )
00136 fprintf(stderr,"++ Direction = axis %d in dataset\n",dcode) ;
00137
00138 DSET_load(inset) ;
00139 if( !DSET_LOADED(inset) ){
00140 fprintf(stderr,"*** Can't load dataset %s\n",argv[iarg]); exit(1);
00141 }
00142 brim = mri_copy( DSET_BRICK(inset,0) ) ;
00143 DSET_unload(inset) ;
00144 EDIT_substitute_brick( outset , 0 , brim->kind , mri_data_pointer(brim) ) ;
00145 nftot = THD_dataset_rowfillin( outset , 0 , dcode , maxgap ) ;
00146 fprintf(stderr,"++ Number of voxels filled = %d\n",nftot) ;
00147 DSET_write(outset) ;
00148 exit(0) ;
00149 }