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  

3destpdf.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 /*---------------------------------------------------------------------------*/
00008 /*
00009   Program to estimate the PDF for a dataset.
00010 
00011   File:    3destpdf.c
00012   Author:  B. Douglas Ward
00013   Date:    20 January 2000
00014 
00015 */
00016 
00017 /*---------------------------------------------------------------------------*/
00018 
00019 #define PROGRAM_NAME "3destpdf"                      /* name of this program */
00020 #define PROGRAM_AUTHOR "B. D. Ward"                        /* program author */
00021 #define PROGRAM_DATE "20 January 2000"           /* date of last program mod */
00022 
00023 /*---------------------------------------------------------------------------*/
00024 /*
00025   Include header files.
00026 */
00027 
00028 
00029 #include "mrilib.h"
00030 
00031 
00032 /*---------------------------------------------------------------------------*/
00033 /*
00034   Global variables and constants.
00035 */
00036 
00037 static char * anat_filename = NULL;      /* file name for input anat dataset */
00038 
00039 static THD_3dim_dataset * anat;                 /* input anatomical dataset  */
00040 
00041 static float min_val_float;                 /* minimum voxel intensity limit */
00042 static float max_val_float;                 /* maximum voxel intensity limit */
00043 
00044 static Boolean quiet = FALSE;            /* flag for suppress screen output */
00045 
00046 #define MAX_STRING_LENGTH 80
00047 
00048 /*---------------------------------------------------------------------------*/
00049 /*
00050    Print error message and stop.
00051 */
00052 
00053 void estPDF_error (char * message)
00054 {
00055   fprintf (stderr, "\n");
00056   fprintf (stderr, "%s Error: %s \n", PROGRAM_NAME, message);
00057   exit(1);
00058 }
00059 
00060 
00061 /*---------------------------------------------------------------------------*/
00062 
00063 /** macro to test a malloc-ed pointer for validity **/
00064 
00065 #define MTEST(ptr) \
00066 if((ptr)==NULL) \
00067 ( estPDF_error ("Cannot allocate memory") )
00068      
00069 /*---------------------------------------------------------------------------*/
00070 /*
00071   Include source code.
00072 */
00073 
00074 #include "estpdf3.c"                    /* code for PDF estimation */
00075 
00076 
00077 /*---------------------------------------------------------------------------*/
00078 /*
00079    Routine to display 3destpdf help menu.
00080 */
00081 
00082 void display_help_menu()
00083 {
00084   printf 
00085     (
00086      "This program estimates the PDF for a dataset.\n\n"
00087      "Usage: \n"
00088      "3destpdf \n"
00089      "-anat filename    Filename of anat dataset to be segmented            \n"
00090       );
00091   
00092   exit(0);
00093 }
00094 
00095 
00096 /*---------------------------------------------------------------------------*/
00097 /*
00098   Routine to get user specified input options.
00099 */
00100 
00101 void get_options
00102 (
00103   int argc,                        /* number of input arguments */
00104   char ** argv                     /* array of input arguments */ 
00105 )
00106 
00107 {
00108   int nopt = 1;                     /* input option argument counter */
00109   int ival, index;                  /* integer input */
00110   float fval;                       /* float input */
00111   char message[MAX_STRING_LENGTH];  /* error message */
00112 
00113 
00114   /*----- does user request help menu? -----*/
00115   if (argc < 2 || strncmp(argv[1], "-help", 5) == 0)  display_help_menu();  
00116    
00117 
00118   /*----- main loop over input options -----*/
00119   while (nopt < argc )
00120     {
00121 
00122       /*-----   -anat filename   -----*/
00123       if (strncmp(argv[nopt], "-anat", 5) == 0)
00124         {
00125           nopt++;
00126           if (nopt >= argc)  estPDF_error ("need argument after -anat ");
00127           anat_filename = malloc (sizeof(char) * MAX_STRING_LENGTH);
00128           MTEST (anat_filename);
00129           strcpy (anat_filename, argv[nopt]);
00130 
00131           anat = THD_open_one_dataset (anat_filename);
00132           if (!ISVALID_3DIM_DATASET (anat))
00133             {
00134               sprintf (message, "Can't open dataset: %s\n", anat_filename); 
00135               estPDF_error (message); 
00136             } 
00137           THD_load_datablock (anat->dblk); 
00138           if (DSET_ARRAY(anat,0) == NULL)
00139             {
00140               sprintf (message, "Can't access data: %s\n", anat_filename); 
00141               estPDF_error (message); 
00142             }
00143 
00144           nopt++;
00145           continue;
00146         }
00147       
00148 
00149       /*----- unknown command -----*/
00150       sprintf(message,"Unrecognized command line option: %s\n", argv[nopt]);
00151       estPDF_error (message);
00152       
00153     }
00154 
00155   
00156 }
00157 
00158 
00159 /*---------------------------------------------------------------------------*/
00160 /*
00161   Program initialization.
00162 */
00163 
00164 void initialize_program 
00165 (
00166   int argc,                        /* number of input arguments */
00167   char ** argv                     /* array of input arguments */ 
00168 )
00169 
00170 {
00171   float parameters [DIMENSION];    /* parameters for PDF estimation */
00172   Boolean ok = TRUE;               /* flag for successful PDF estimation */
00173 
00174   int nx, ny, nz, nxy, nxyz, ixyz;       /* voxel counters */
00175   int n;                                 /* histogram bin index */
00176   short * sfim = NULL;                   /* pointer to anat data */
00177   short * rfim = NULL;                   /* truncated data */ 
00178   int icount;
00179   int lower_cutoff = 25;
00180 
00181   /*----- Get operator inputs -----*/
00182   get_options (argc, argv);
00183 
00184 
00185   /*----- Initialize local variables -----*/
00186   if (anat == NULL)  estPDF_error ("Unable to read anat dataset");
00187   nx = DSET_NX(anat);   ny = DSET_NY(anat);   nz = DSET_NZ(anat);
00188   nxy = nx*ny;   nxyz = nxy*nz;
00189   sfim  = (short *) DSET_BRICK_ARRAY(anat,0) ;
00190   if (sfim == NULL)  estPDF_error ("Unable to read anat dataset");
00191   rfim = (short *) malloc (sizeof(short) * nxyz);   MTEST (rfim);
00192 
00193 
00194   /*----- Just use voxels whose intensity is above the lower cutoff -----*/
00195   icount = 0;
00196   for (ixyz = 0;  ixyz < nxyz;  ixyz++)
00197     if (sfim[ixyz] > lower_cutoff)
00198       {
00199         rfim[icount] = sfim[ixyz];
00200         icount++;
00201       }
00202   printf ("%d voxels above lower cutoff = %d \n", icount, lower_cutoff);
00203 
00204 
00205   /*----- Get PDF estimate and set voxel intensity limits -----*/
00206   estpdf_short (icount, rfim, parameters);
00207   min_val_float = parameters[4] - 2.0*parameters[5];
00208   max_val_float = parameters[7] + 2.0*parameters[8];
00209   
00210    
00211   if (! quiet)
00212     {
00213       printf ("\n");
00214       printf ("Control inputs: \n");
00215       printf ("anat filename = %s \n", anat_filename);
00216       printf ("min value = %f \n", min_val_float);
00217       printf ("max value = %f \n", max_val_float);
00218     }
00219 
00220 
00221 }
00222 
00223 
00224 /*---------------------------------------------------------------------------*/
00225 /*
00226   This is the main routine for program 3destpdf.
00227 */
00228 
00229 int main
00230 (
00231   int argc,                /* number of input arguments */
00232   char ** argv             /* array of input arguments */ 
00233 )
00234 
00235 {
00236 
00237   /*----- Identify software -----*/
00238   printf ("\n\n");
00239   printf ("Program: %s \n", PROGRAM_NAME);
00240   printf ("Author:  %s \n", PROGRAM_AUTHOR);
00241   printf ("Date:    %s \n", PROGRAM_DATE);
00242   printf ("\n");
00243 
00244   
00245   /*----- Program initialization -----*/
00246   initialize_program (argc, argv);
00247 
00248   
00249 
00250 }
00251 
00252 /*---------------------------------------------------------------------------*/
00253 
00254 
00255 
00256 
00257 
00258 
 

Powered by Plone

This site conforms to the following standards: