Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

3dMax.c File Reference

#include "mrilib.h"
#include "thd_shear3d.h"

Go to the source code of this file.


Functions

void Print_Header_MinMax (int Minflag, int Maxflag, THD_3dim_dataset *dset)
void Max_func (int Minflag, int Maxflag, int Meanflag, int Countflag, int Posflag,\int Negflag, int Zeroflag, THD_3dim_dataset *dset, byte *mmm, int mmvox)
void Max_tsfunc (double tzero, double tdelta, int npts, float ts[], double ts_mean, double ts_slope, void *ud, int nbriks, float *val)
int main (int argc, char *argv[])
void Print_Header_MinMax (Minflag, Maxflag, dset) int Minflag

Variables

int datum = MRI_float
float minvalue = 1E10
float maxvalue = -1E10
void Maxflag
THD_3dim_datasetdset
bytemmm
int mmvox

Function Documentation

int main int    argc,
char *    argv[]
 

compute the overall minimum and maximum voxel values for a dataset

Definition at line 15 of file 3dMax.c.

References ADN_ntt, ADN_ttdel, ADN_ttorg, ADN_tunits, AFNI_logger(), argc, datum, DSET_delete, DSET_NVALS, DSET_NVOX, EDIT_dset_items(), free, i, ISVALID_DSET, machdep(), mainENTRY, MAKER_4D_to_typed_fbuc(), MASTER_SHORTHELP_STRING, Max_func(), Max_tsfunc(), maxvalue, minvalue, mmm, mmvox, Print_Header_MinMax(), THD_automask(), THD_makemask(), THD_open_dataset(), and UNITS_SEC_TYPE.

00016 {
00017    THD_3dim_dataset * old_dset , * new_dset ;  /* input and output datasets */
00018    int nopt, nbriks;
00019    int slow_flag, quick_flag, min_flag, max_flag, mean_flag, automask,count_flag;
00020    int positive_flag, negative_flag, zero_flag;
00021    byte * mmm=NULL ;
00022    int    mmvox=0 ;
00023    int nxyz, i;
00024    MRI_IMAGE *anat_im = NULL;
00025 
00026 
00027    /*----- Read command line -----*/
00028    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00029       printf("Usage: 3dMax [options] dataset\n"
00030              "Compute maximum and/or minimum voxel values of an input dataset\n"
00031              "\n"
00032              "The output is a number to the console.  The input dataset\n"
00033              "may use a sub-brick selection list, as in program 3dcalc.\n"
00034              "Options :\n"
00035              "  -quick = get the information from the header only (default)\n"
00036              "  -slow = read the whole dataset to find the min and max values\n"
00037              "  -min = print the minimum value in dataset\n"
00038              "  -max = print the minimum value in dataset (default)\n"
00039              "  -mean = print the mean value in dataset (implies slow)\n"
00040              "  -count = print the number of voxels included (implies slow)\n"
00041              "  -positive = include only positive voxel values (implies slow)\n"
00042              "  -negative = include only negative voxel values (implies slow)\n"
00043              "  -zero = include only zero voxel values (implies slow)\n"
00044              "  -non-positive = include only voxel values 0 or negative (implies slow)\n"
00045              "  -non-negative = include only voxel values 0 or greater (implies slow)\n"
00046              "  -non-zero = include only voxel values not equal to 0 (implies slow)\n"
00047              "  -mask dset = use dset as mask to include/exclude voxels\n"
00048              "  -automask = automatically compute mask for dataset\n"
00049              "    Can not be combined with -mask\n"
00050              "  -help = print this help screen\n"
00051            ) ;
00052       printf("\n" MASTER_SHORTHELP_STRING ) ;
00053       exit(0) ;
00054    }
00055 
00056    mainENTRY("3dMax main"); machdep(); AFNI_logger("3dMax",argc,argv);
00057 
00058    nopt = 1 ;
00059 
00060    min_flag  = 0;
00061    max_flag = -1;
00062    mean_flag = 0;
00063    slow_flag = 0;
00064    quick_flag = -1;
00065    automask = 0;
00066    count_flag = 0;
00067    positive_flag = -1;
00068    negative_flag = -1;
00069    zero_flag = -1;
00070 
00071    datum = MRI_float;
00072    while( nopt < argc && argv[nopt][0] == '-' ){
00073       if( strcmp(argv[nopt],"-quick") == 0 ){
00074         quick_flag = 1;
00075         nopt++; continue;
00076       }
00077 
00078       if( strcmp(argv[nopt],"-slow") == 0 ){
00079         slow_flag = 1;
00080         nopt++; continue;
00081       }
00082 
00083       if( strcmp(argv[nopt],"-min") == 0 ){
00084         min_flag = 1;
00085         nopt++; continue;
00086       }
00087 
00088       if( strcmp(argv[nopt],"-max") == 0 ){
00089         max_flag = 1;
00090         nopt++; continue;
00091       }
00092 
00093       if( strcmp(argv[nopt],"-mean") == 0 ){
00094         mean_flag = 1;
00095         nopt++; continue;
00096       }
00097 
00098       if( strcmp(argv[nopt],"-count") == 0 ){
00099         count_flag = 1;
00100         nopt++; continue;
00101       }
00102 
00103       if( strcmp(argv[nopt],"-positive") == 0 ){
00104         if(positive_flag!=-1) {
00105           fprintf(stderr, "***Can not use multiple +/-/0 options");
00106           exit(1) ;
00107         }
00108         positive_flag = 1;
00109         negative_flag = 0;
00110         zero_flag = 0;
00111         nopt++; continue;
00112       }
00113 
00114       if( strcmp(argv[nopt],"-negative") == 0 ){
00115         if(positive_flag!=-1) {
00116           fprintf(stderr, "***Can not use multiple +/-/0 options");
00117           exit(1) ;
00118         }
00119         positive_flag = 0;
00120         negative_flag = 1;
00121         zero_flag = 0;
00122         nopt++; continue;
00123       }
00124 
00125       if( strcmp(argv[nopt],"-zero") == 0 ){
00126         if(positive_flag!=-1) {
00127           fprintf(stderr, "***Can not use multiple +/-/0 options");
00128           exit(1) ;
00129         }
00130         positive_flag = 0;
00131         negative_flag = 0;
00132         zero_flag = 1;
00133         nopt++; continue;
00134       }
00135 
00136       if( strcmp(argv[nopt],"-non-positive") == 0 ){
00137         if(positive_flag!=-1) {
00138           fprintf(stderr, "***Can not use multiple +/-/0 options");
00139           exit(1) ;
00140         }
00141         positive_flag = 0;
00142         negative_flag = 1;
00143         zero_flag = 1;
00144         nopt++; continue;
00145       }
00146       if( strcmp(argv[nopt],"-non-negative") == 0 ){
00147         if(positive_flag!=-1) {
00148           fprintf(stderr, "***Can not use multiple +/-/0 options");
00149           exit(1) ;
00150         }
00151         positive_flag = 1;
00152         negative_flag = 0;
00153         zero_flag = 1;
00154         nopt++; continue;
00155       }
00156 
00157       if( strcmp(argv[nopt],"-non-zero") == 0 ){
00158         if(positive_flag!=-1) {
00159           fprintf(stderr, "***Can not use multiple +/-/0 options");
00160           exit(1) ;
00161         }
00162         positive_flag = 1;
00163         negative_flag = 1;
00164         zero_flag = 0;
00165         nopt++; continue;
00166       }
00167 
00168 
00169       if( strcmp(argv[nopt],"-autoclip") == 0 ||
00170           strcmp(argv[nopt],"-automask") == 0   ){
00171 
00172          if( mmm != NULL ){
00173            fprintf(stderr,"** ERROR: can't use -autoclip/mask with -mask!\n");
00174            exit(1) ;
00175          }
00176          automask = 1 ; nopt++ ; continue ;
00177       }
00178 
00179       if( strcmp(argv[nopt],"-mask") == 0 ){
00180          THD_3dim_dataset * mask_dset ;
00181          if( automask ){
00182            fprintf(stderr,"** ERROR: can't use -mask with -automask!\n");
00183            exit(1) ;
00184          }
00185          mask_dset = THD_open_dataset(argv[++nopt]) ;
00186          if( mask_dset == NULL ){
00187             fprintf(stderr,"** ERROR: can't open -mask dataset!\n"); exit(1);
00188          }
00189          if( mmm != NULL ){
00190             fprintf(stderr,"** ERROR: can't have 2 -mask options!\n"); exit(1);
00191          }
00192          mmm = THD_makemask( mask_dset , 0 , 1.0,-1.0 ) ;
00193          mmvox = DSET_NVOX( mask_dset ) ;
00194 
00195          DSET_delete(mask_dset) ; nopt++ ; continue ;
00196       }
00197 
00198       fprintf(stderr, "*** Error - unknown option %s\n", argv[nopt]);
00199       exit(1);
00200    }
00201 
00202    if(((mmm!=NULL) && (quick_flag))||(automask &&quick_flag)) {
00203       if(quick_flag==1)
00204          fprintf(stderr, "+++ Warning - can't have quick option with mask\n");
00205       quick_flag = 0;
00206       slow_flag = 1;
00207    }
00208 
00209    if(max_flag==-1) {                   /* if max_flag is not set by user,*/
00210      if(min_flag || mean_flag ||count_flag)   /* check if other user options set */
00211          max_flag = 0;
00212       else
00213         max_flag = 1;                  /* otherwise check only for max */
00214      }
00215 
00216    if((mean_flag==1)||(count_flag==1)||(positive_flag!=-1))  /* mean flag or count_flag implies slow */
00217      slow_flag = 1;
00218 
00219    /* check slow and quick options */
00220    if((slow_flag)&&(quick_flag!=1))  /* if user asked for slow give it to him */
00221       quick_flag = 0;
00222    else
00223       quick_flag = 1;
00224 
00225    if((max_flag==0)&&(min_flag==0))   /* if the user only asked for mean */
00226      quick_flag = 0;                  /*  no need to do quick way */
00227 
00228    if((quick_flag) && ((positive_flag==1)||(negative_flag==1)||(zero_flag==1)))
00229      fprintf(stderr, "+++ Warning - ignoring +/-/0 flags for quick computations\n");
00230 
00231    if(positive_flag==-1) {   /* if no +/-/0 options set, allow all voxels */
00232      positive_flag = 1;
00233      negative_flag = 1;
00234      zero_flag = 1;
00235    }
00236 
00237    /*----- read input dataset -----*/
00238 
00239    if( nopt >= argc ){
00240       fprintf(stderr,"*** No input dataset!?\n"); exit(1);
00241    }
00242 
00243    old_dset = THD_open_dataset( argv[nopt] ) ;
00244    if( !ISVALID_DSET(old_dset) ){
00245       fprintf(stderr,"*** Can't open dataset %s\n",argv[nopt]); exit(1);
00246    }
00247 
00248    nxyz = DSET_NVOX(old_dset) ;
00249    if( mmm != NULL && mmvox != nxyz ){
00250       fprintf(stderr,"** Mask and input datasets not the same size!\n") ;
00251       exit(1) ;
00252    }
00253 
00254    if(automask && mmm == NULL ){
00255       mmm = THD_automask( old_dset ) ;
00256       for(i=0;i<nxyz;i++) {
00257         if(mmm[i]!=0) ++mmvox;
00258       }
00259    }
00260 
00261    if(quick_flag)
00262       Print_Header_MinMax(min_flag, max_flag, old_dset);
00263  
00264    if(slow_flag!=1)
00265       exit(0);
00266 
00267    Max_func(min_flag, max_flag, mean_flag,count_flag,positive_flag, negative_flag, zero_flag,\
00268       old_dset, mmm, mmvox);
00269 
00270    if(mmm!=NULL)
00271      free(mmm);
00272    exit(0);
00273 
00274 /* unused code time series method for extracting data */
00275 #if 0
00276    EDIT_dset_items( old_dset ,
00277                     ADN_ntt    , DSET_NVALS(old_dset) ,
00278                     ADN_ttorg  , 0.0 ,
00279                     ADN_ttdel  , 1.0 ,
00280                     ADN_tunits , UNITS_SEC_TYPE ,
00281                     NULL ) ;
00282    nbriks = 1;
00283 
00284    /*------------- ready to compute new min, max -----------*/
00285    new_dset = MAKER_4D_to_typed_fbuc(
00286                  old_dset ,             /* input dataset */
00287                  "temp" ,               /* output prefix */
00288                  datum ,                /* output datum  */
00289                  0 ,                    /* ignore count  */
00290                  0 ,              /* can't detrend in maker function  KRH 12/02*/
00291                  nbriks ,               /* number of briks */
00292                  Max_tsfunc ,         /* timeseries processor */
00293                  NULL                   /* data for tsfunc */
00294               ) ;
00295    if(min_flag)
00296      printf("%-13.6g ", minvalue); 
00297    if(max_flag)
00298      printf("%-13.6g", maxvalue); 
00299    printf("\n");
00300    exit(0) ;
00301 #endif
00302 }

void Max_func int    Minflag,
int    Maxflag,
int    Meanflag,
int    Countflag,
int    Posflag,
\int    Negflag,
int    Zeroflag,
THD_3dim_dataset   dset,
byte   mmm,
int    mmvox
[static]
 

Referenced by main().

void Max_tsfunc double    tzero,
double    tdelta,
int    npts,
float    ts[],
double    ts_mean,
double    ts_slope,
void *    ud,
int    nbriks,
float *    val
[static]
 

Referenced by main().

void Print_Header_MinMax Minflag   ,
Maxflag   ,
dset   
[static]
 

Print the minimum and maximum values from the header

Referenced by main().

void Print_Header_MinMax int    Minflag,
int    Maxflag,
THD_3dim_dataset   dset
[static]
 


Variable Documentation

int datum = MRI_float [static]
 

Definition at line 6 of file 3dMax.c.

Referenced by main().

THD_3dim_dataset * dset
 

Definition at line 365 of file 3dMax.c.

Maxflag
 

Definition at line 364 of file 3dMax.c.

float maxvalue = -1E10 [static]
 

Definition at line 13 of file 3dMax.c.

Referenced by main().

float minvalue = 1E10 [static]
 

Definition at line 13 of file 3dMax.c.

Referenced by main().

byte* mmm
 

Definition at line 366 of file 3dMax.c.

Referenced by AFNI_make_affwarp_mat(), AFNI_make_affwarp_matvec(), AFNI_vnlist_func_overlay(), AREN_set_size(), BFIT_prepare_dataset(), clustedit3D(), CORREL_main(), CREN_set_interp(), CREN_set_render_mode(), DSET_cor(), HISTO_main(), main(), make_peel_mask(), mask_count(), MASKAVE_main(), MCW_textwin_alter(), MREN_set_size(), MRI_autobbox(), mri_automask_image(), mri_automask_imarr(), mri_warp3D_align_setup(), process_NIML_MRI_IMAGE(), SCAT_main(), THD_automask(), THD_cmass(), THD_countmask(), THD_dataset_info(), THD_init_session(), THD_makemask(), THD_mask_clip_neighbors(), THD_mask_clust(), THD_mask_dilate(), THD_mask_distize(), THD_mask_erode(), THD_mask_fillin_completely(), THD_mask_fillin_once(), THD_peel_mask(), and zedit_mask().

int mmvox
 

Definition at line 367 of file 3dMax.c.

Referenced by main().

 

Powered by Plone

This site conforms to the following standards: