1 /* ----------------------------- MNI Header ----------------------------------- 2 @NAME : mnitominc.h 3 @DESCRIPTION: Header file for mnitominc 4 @GLOBALS : 5 @CALLS : 6 @CREATED : December 9, 1992 (Peter Neelin) 7 @MODIFIED : 8 * $Log: mnitominc.h,v $ 9 * Revision 6.1 1999-10-29 17:52:06 neelin 10 * Fixed Log keyword 11 * 12 * Revision 6.0 1997/09/12 13:23:27 neelin 13 * Release of minc version 0.6 14 * 15 * Revision 5.0 1997/08/21 13:24:28 neelin 16 * Release of minc version 0.5 17 * 18 * Revision 4.0 1997/05/07 20:00:05 neelin 19 * Release of minc version 0.4 20 * 21 * Revision 3.0 1995/05/15 19:31:02 neelin 22 * Release of minc version 0.3 23 * 24 * Revision 2.0 1994/09/28 10:33:18 neelin 25 * Release of minc version 0.2 26 * 27 * Revision 1.11 94/09/28 10:33:13 neelin 28 * Pre-release 29 * 30 * Revision 1.10 94/09/26 08:58:12 neelin 31 * Changed default to -noclobber. 32 * 33 * Revision 1.9 93/08/30 16:44:30 neelin 34 * Added -slcstep option. 35 * Fixed -field_of_view option. 36 * Changed -xstep/-ystep to -colstep -rowstep. 37 * 38 * Revision 1.8 93/08/11 15:24:29 neelin 39 * Added RCS logging to source. 40 * 41 @COPYRIGHT : 42 Copyright 1993 Peter Neelin, McConnell Brain Imaging Centre, 43 Montreal Neurological Institute, McGill University. 44 Permission to use, copy, modify, and distribute this 45 software and its documentation for any purpose and without 46 fee is hereby granted, provided that the above copyright 47 notice appear in all copies. The author and McGill University 48 make no representations about the suitability of this 49 software for any purpose. It is provided "as is" without 50 express or implied warranty. 51 ---------------------------------------------------------------------------- */ 52 /* Some constants */ 53 54 #define NORMAL_STATUS 0 55 #define ERROR_STATUS 1 56 #define TRUE 1 57 #define FALSE 0 58 #define MIN_VALID_CHAR ' ' 59 #define MAX_VALID_CHAR '\177' 60 #define PADDING_CHAR ' ' 61 #define SEC_PER_MIN 60.0 62 #define EPSILON 100.0*FLT_EPSILON 63 64 /* Constants for argument parsing */ 65 #define MAX_VOL_IMGS 128 66 #define DEFAULT_NSLICES 15 67 #define IMAGE_DIMS 2 68 #define MAX_DIMS 4 69 #define DEF_ORIENT -1 70 #define TRANSVERSE 0 71 #define SAGITTAL 1 72 #define CORONAL 2 73 74 /* Constants for mni files */ 75 #define BLOCK_SIZE 512 76 #define MNI_HEADER_SIZE BLOCK_SIZE 77 #define MNI_FILE_TYPE 1 78 #define NIL_FILE_TYPE 2 79 #define MNI_STX_XBRAIN 67.0 80 #define MNI_STX_YBRAIN 86.0 81 #define MNI_STX_ZBRAIN 75.0 82 #define MNI_STX_PBRAIN 50.0 83 #define MNI_STX_XACLOC 0.0 84 #define MNI_STX_YACLOC 16.0 85 #define MNI_STX_NPIXEL 128 86 #define MNI_STX_FACTOR 100.0 87 #define MNI_STX_XFOV MNI_STX_NPIXEL*MNI_STX_XBRAIN/MNI_STX_PBRAIN 88 #define MNI_STX_YFOV MNI_STX_NPIXEL*MNI_STX_YBRAIN/MNI_STX_PBRAIN 89 #define MNI_STX_ZFOV MNI_STX_NPIXEL*MNI_STX_ZBRAIN/MNI_STX_PBRAIN 90 #define MNI_STX_XSCALE MNI_STX_XBRAIN/MNI_STX_FACTOR 91 #define MNI_STX_YSCALE MNI_STX_YBRAIN/MNI_STX_FACTOR 92 #define MNI_STX_ZSCALE MNI_STX_ZBRAIN/MNI_STX_FACTOR 93 #define MNI_FOV 256.0 94 #define NIL_FOV 250.0 95 #define MNI_DIR (1.0) 96 #define NIL_DIR (-1.0) 97 #define MNI_VMIN 0.0 98 #define MNI_VMAX 255.0 99 #define NIL_VMIN 0.0 100 #define NIL_VMAX 4095.0 101 #define MNI_MRI_SCAN 1 102 #define MNI_SCX_SCAN 2 103 #define MNI_STX_SCAN 3 104 #define MNI_POS_SCAN 4 105 #define MNI_TRANSVERSE 100 106 #define MNI_CORONAL 200 107 #define MNI_SAGITTAL 300 108 #define MNI_POSITOME_MASK 0 109 #define MNI_CORNER_XSIZE 12 110 #define MNI_CORNER_YSIZE 7 111 #define MNI_LOC_OFFSET 212 112 #define MNI_LOC_NIMAGES 230 113 #define MNI_LOC_MATYPE 238 114 #define MNI_LOC_SCANNER_ID 200 115 #define MNI_LOC_ORIENTATION 204 116 #define MNI_LOC_PATNAM 0 117 #define MNI_PATNAM_LENGTH 23 118 #define MNI_LOC_PATNUM 23 119 #define MNI_PATNUM_LENGTH 14 120 #define MNI_LOC_ACQDAT 42 121 #define MNI_ACQDAT_LENGTH 10 122 #define MNI_LOC_ACQTIM 52 123 #define MNI_ACQTIM_LENGTH 10 124 #define MNI_LOC_ISOTOPE 129 125 #define MNI_ISOTOPE_LENGTH 14 126 #define MNI_LOC_DOSE 143 127 #define MNI_DOSE_LENGTH 14 128 #define MNI_LOC_INJTIM 157 129 #define MNI_INJTIM_LENGTH 10 130 #define MNI_LOC_CORR_MASK 196 131 #define MNI_XLOC_QSC 0 132 #define MNI_YLOC_QSC 0 133 #define MNI_XLOC_ISEA 4 134 #define MNI_YLOC_ISEA 2 135 #define MNI_XLOC_ZPOS 8 136 #define MNI_YLOC_ZPOS 0 137 #define MNI_XLOC_TIME 0 138 #define MNI_YLOC_TIME 2 139 #define MNI_XLOC_TLEN 4 140 #define MNI_YLOC_TLEN 3 141 142 /* Structure containing information about orientation */ 143 char *orientation_names[][IMAGE_DIMS+1] = { 144 {MIzspace, MIyspace, MIxspace}, 145 {MIxspace, MIzspace, MIyspace}, 146 {MIyspace, MIzspace, MIxspace}, 147 }; 148 149 /* Structure containing information about signs */ 150 char *sign_names[][6] = { 151 {MI_SIGNED, MI_UNSIGNED, MI_SIGNED, MI_SIGNED, MI_SIGNED, MI_SIGNED}, 152 {MI_SIGNED, MI_SIGNED, MI_SIGNED, MI_SIGNED, MI_SIGNED, MI_SIGNED}, 153 {MI_SIGNED, MI_UNSIGNED, MI_UNSIGNED, MI_UNSIGNED, MI_UNSIGNED, MI_UNSIGNED} 154 }; 155 156 /* Argument variables */ 157 char *pname; 158 char *infilename; 159 char *outfilename; 160 int clobber = FALSE; 161 int verbose = TRUE; 162 char *dimname[MAX_VAR_DIMS] = {MItime, NULL, NULL, NULL}; 163 long dimlength[MAX_VAR_DIMS] = {0}; 164 int dimfixed[MAX_VAR_DIMS] = {FALSE, FALSE, TRUE, TRUE}; 165 long nframes; 166 long nslices; 167 int ndims; 168 int orientation = DEF_ORIENT; 169 double field_of_view = 0.0; 170 double xstep = 0.0; 171 double ystep = 0.0; 172 double zstep = 0.0; 173 174 /* Argument table */ 175 ArgvInfo argTable[] = { 176 {NULL, ARGV_HELP, (char *) NULL, (char *) NULL, 177 "Options to specify image orientation. Default = -transverse."}, 178 {"-transverse", ARGV_CONSTANT, (char *) TRANSVERSE, (char *) &orientation, 179 "Transverse images"}, 180 {"-sagittal", ARGV_CONSTANT, (char *) SAGITTAL, (char *) &orientation, 181 "Sagittal images"}, 182 {"-coronal", ARGV_CONSTANT, (char *) CORONAL, (char *) &orientation, 183 "Coronal images"}, 184 {NULL, ARGV_HELP, NULL, NULL, 185 "Options to help specify number of slices and time frames."}, 186 {"-nslices", ARGV_INT, (char *) 1, (char *) &dimlength[1], 187 "Number of slices in volume."}, 188 {"-nframes", ARGV_INT, (char *) 1, (char *) &dimlength[0], 189 "Number of time frames."}, 190 {NULL, ARGV_HELP, NULL, NULL, 191 "Options for writing output file. Default = -noclobber."}, 192 {"-clobber", ARGV_CONSTANT, (char *) TRUE, (char *) &clobber, 193 "Overwrite existing file"}, 194 {"-noclobber", ARGV_CONSTANT, (char *) FALSE, (char *) &clobber, 195 "Don't overwrite existing file"}, 196 {NULL, ARGV_HELP, NULL, NULL, 197 "Options for logging progress. Default = -verbose."}, 198 {"-verbose", ARGV_CONSTANT, (char *) TRUE, (char *) &verbose, 199 "Write messages indicating progress"}, 200 {"-quiet", ARGV_CONSTANT, (char *) FALSE, (char *) &verbose, 201 "Do not write log messages"}, 202 {NULL, ARGV_HELP, NULL, NULL, 203 "Other options."}, 204 {"-field_of_view", ARGV_FLOAT, (char *) 1, (char *) &field_of_view, 205 "Field of view of images (in mm)."}, 206 {"-colstep", ARGV_FLOAT, (char *) 1, (char *) &xstep, 207 "Distance between pixels along columns (in mm)."}, 208 {"-rowstep", ARGV_FLOAT, (char *) 1, (char *) &ystep, 209 "Distance between pixels along rows (in mm)."}, 210 {"-slcstep", ARGV_FLOAT, (char *) 1, (char *) &zstep, 211 "Distance between slices (in mm)."}, 212 {NULL, ARGV_END, NULL, NULL, NULL} 213 }; 214 215 /* Mni format file information */ 216 typedef struct { 217 FILE *fp; 218 int file_type; 219 short offset; 220 short nimages; 221 int npixels; 222 int pix_size; 223 double valid_range[2]; 224 short scanner_id; 225 double xstep; 226 double ystep; 227 double zstep_scale; 228 double xstart; 229 double ystart; 230 short orientation; 231 char patient_name[MNI_PATNAM_LENGTH + 1]; 232 char patient_num[MNI_PATNUM_LENGTH + 1]; 233 char start_time[MNI_ACQDAT_LENGTH + MNI_ACQTIM_LENGTH + 2]; 234 char isotope[MNI_ISOTOPE_LENGTH + 1]; 235 char dose_string[MNI_DOSE_LENGTH + 1]; 236 double dose; 237 char dose_units[10]; 238 char injection_time[MNI_INJTIM_LENGTH + 1]; 239 } mni_header_type; 240 241 typedef struct { 242 unsigned char *image; 243 long npixels; 244 long image_pix; 245 int pix_size; 246 long image_size; 247 double minimum; 248 double maximum; 249 double zposition; 250 double time; 251 double time_length; 252 } mni_image_type; 253 254 /* Function declarations */ 255 void parse_args(int argc, char *argv[], mni_header_type *mni_header); 256 void usage_error(char *progname); 257 int get_mni_header(char *file, mni_header_type *mni_header); 258 int get_mni_image(mni_header_type *mni_header, mni_image_type *mni_image, 259 int image_num); 260 int dblcmp(double dbl1, double dbl2, double epsilon); 261 262