Doxygen Source Code Documentation
3dMedianFilter.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Function Documentation
|
---------- Adapted from 3dZeropad.c by RWCox - 08 Aug 2001 ----------* Definition at line 5 of file 3dMedianFilter.c. References ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, AFNI_logger(), argc, DSET_BRICK, DSET_BRIKNAME, DSET_load, DSET_LOADED, DSET_NVALS, DSET_write, EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), free, machdep(), mainENTRY, MRI_FLOAT_PTR, mri_medianfilter(), PRINT_VERSION, strtod(), THD_automask(), THD_automask_extclip(), THD_automask_verbose(), THD_filename_ok(), THD_open_dataset(), tross_Copy_History(), and tross_Make_History().
00006 { 00007 float irad=1.5 ; 00008 int nrep=1 ; 00009 char *prefix = "MedianFilter" ; 00010 int iarg , verb=0 , do_mask=0 ; 00011 THD_3dim_dataset *inset , *outset ; 00012 MRI_IMAGE *imout ; 00013 byte *mask=NULL ; 00014 00015 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){ 00016 printf("Usage: 3dMedianFilter [options] dataset\n" 00017 "Computes the median in a spherical nbhd around each point in the\n" 00018 "input to produce the output.\n" 00019 "\n" 00020 "Options:\n" 00021 " -irad x = Radius in voxels of spherical regions\n" 00022 " -verb = Be verbose during run\n" 00023 " -prefix pp = Use 'pp' for prefix of output dataset\n" 00024 " -automask = Create a mask (a la 3dAutomask)\n" 00025 "\n" 00026 "Output dataset is always stored in float format. If the input\n" 00027 "dataset has more than 1 sub-brick, only sub-brick #0 is processed.\n" 00028 "\n" 00029 "-- Feb 2005 - RWCox\n" 00030 ) ; 00031 exit(0) ; 00032 } 00033 00034 mainENTRY("3dMedianFilter main"); machdep(); AFNI_logger("3dMedianFilter",argc,argv); 00035 PRINT_VERSION("3dMedianFilter") ; 00036 00037 /*-- scan command line --*/ 00038 00039 iarg = 1 ; 00040 while( iarg < argc && argv[iarg][0] == '-' ){ 00041 00042 if( strncmp(argv[iarg],"-automask",5) == 0 ){ 00043 do_mask++ ; iarg++ ; continue ; 00044 } 00045 00046 if( strncmp(argv[iarg],"-verb",5) == 0 ){ 00047 verb++ ; iarg++ ; continue ; 00048 } 00049 00050 if( strcmp(argv[iarg],"-irad") == 0 ){ 00051 irad = strtod( argv[++iarg] , NULL ) ; 00052 if( irad < 1.0 ){ 00053 fprintf(stderr,"*** Illegal value after -irad!\n"); exit(1); 00054 } 00055 iarg++ ; continue ; 00056 } 00057 00058 if( strcmp(argv[iarg],"-prefix") == 0 ){ 00059 prefix = argv[++iarg] ; 00060 if( !THD_filename_ok(prefix) ){ 00061 fprintf(stderr,"*** Illegal value after -prefix!\n"); exit(1); 00062 } 00063 iarg++ ; continue ; 00064 } 00065 00066 fprintf(stderr,"*** Unknown option: %s\n",argv[iarg]); exit(1) ; 00067 } 00068 00069 if( iarg >= argc ){ 00070 fprintf(stderr,"*** No dataset name on command line?\n"); exit(1); 00071 } 00072 00073 /*-- read input --*/ 00074 00075 inset = THD_open_dataset( argv[iarg] ) ; 00076 if( inset == NULL ){ 00077 fprintf(stderr,"** ERROR: Can't open dataset %s\n",argv[iarg]); exit(1); 00078 } 00079 DSET_load( inset ) ; 00080 if( !DSET_LOADED(inset) ){ 00081 fprintf(stderr,"** ERROR: can't load dataset %s\n",argv[iarg]); exit(1); 00082 } 00083 if( DSET_NVALS(inset) > 1 ){ 00084 fprintf(stderr,"++ WARNING: only processing sub-brick #0\n") ; 00085 } 00086 00087 if( do_mask ){ 00088 THD_automask_verbose( verb ) ; 00089 THD_automask_extclip( 1 ) ; 00090 mask = THD_automask( inset ) ; 00091 } 00092 00093 imout = mri_medianfilter( DSET_BRICK(inset,0) , irad , mask , verb ) ; 00094 free((void *)mask) ; 00095 00096 outset = EDIT_empty_copy( inset ) ; 00097 EDIT_dset_items( outset , 00098 ADN_prefix , prefix , 00099 ADN_nvals , 1 , 00100 ADN_ntt , 0 , 00101 ADN_none ) ; 00102 EDIT_substitute_brick( outset , 0 , MRI_float , MRI_FLOAT_PTR(imout) ) ; 00103 tross_Copy_History( inset , outset ) ; 00104 tross_Make_History( "3dMedianFilter" , argc,argv , outset ) ; 00105 DSET_write(outset) ; 00106 fprintf(stderr,"++ output dataset: %s\n",DSET_BRIKNAME(outset)) ; 00107 exit(0) ; 00108 } |