1 /* ----------------------------- MNI Header ----------------------------------- 2 @NAME : dicom_to_minc.h 3 @DESCRIPTION: Header file for dicom_to_minc.h 4 @METHOD : 5 @GLOBALS : 6 @CALLS : 7 @CREATED : January 28, 1997 (Peter Neelin) 8 @MODIFIED : 9 * $Log: dicom_to_minc.h,v $ 10 * Revision 1.10 2010-11-23 23:30:50 claude 11 * dcm2mnc: fixed seg fault bug (Claude) and added b-matrix (Ilana) 12 * 13 * Revision 1.9 2007-06-08 20:28:57 ilana 14 * added several fields to mincheader (dicom elements and found in ASCONV header) 15 * 16 * Revision 1.8 2006/04/09 15:33:10 bert 17 * Add flags and fields for DTI 18 * 19 * Revision 1.7 2005/11/04 22:25:34 bert 20 * Change COORDINATE_EPSILON again, now set to 0.005 21 * 22 * Revision 1.6 2005/10/26 23:43:55 bert 23 * Fix COORDINATE_EPSILON at 0.0001 24 * 25 * Revision 1.5 2005/07/14 19:00:30 bert 26 * Changes ported from 1.X branch 27 * 28 * Revision 1.4.2.2 2005/06/20 22:00:26 bert 29 * Simplify Image_Data structure, add is_siemens_mosaic() function declaration 30 * 31 * Revision 1.4.2.1 2005/05/12 21:16:47 bert 32 * Initial checkin 33 * 34 * Revision 1.4 2005/04/28 17:10:22 bert 35 * Added width information to General_Info and File_Info structures 36 * 37 * Revision 1.3 2005/04/20 23:14:32 bert 38 * Remove unnecessary fields, add copy_spi_to_acr() function definition 39 * 40 * Revision 1.2 2005/03/02 18:25:13 bert 41 * Add Mri_Names and Volume_Names 42 * 43 * Revision 1.1 2005/02/17 16:38:10 bert 44 * Initial checkin, revised DICOM to MINC converter 45 * 46 * Revision 1.1.1.1 2003/08/15 19:52:55 leili 47 * Leili's dicom server for sonata 48 * 49 * Revision 1.6 2002/04/26 03:27:03 rhoge 50 * fixed MrProt problem - replaced fixed lenght char array with malloc 51 * 52 * Revision 1.5 2002/04/08 17:26:34 rhoge 53 * added additional sequence info to minc header 54 * 55 * Revision 1.4 2002/03/27 18:57:50 rhoge 56 * added diffusion b value 57 * 58 * Revision 1.3 2002/03/19 13:13:57 rhoge 59 * initial working mosaic support - I think time is scrambled though. 60 * 61 * Revision 1.2 2001/12/31 18:27:21 rhoge 62 * modifications for dicomreader processing of Numaris 4 dicom files - at 63 * this point code compiles without warning, but does not deal with 64 * mosaiced files. Also will probably not work at this time for Numaris 65 * 3 .ima files. dicomserver may also not be functional... 66 * 67 * Revision 1.1.1.1 2000/11/30 02:13:15 rhoge 68 * imported sources to CVS repository on amoeba 69 * 70 * Revision 6.1 1999/10/29 17:51:59 neelin 71 * Fixed Log keyword 72 * 73 * Revision 6.0 1997/09/12 13:24:27 neelin 74 * Release of minc version 0.6 75 * 76 * Revision 5.0 1997/08/21 13:25:26 neelin 77 * Release of minc version 0.5 78 * 79 * Revision 4.0 1997/05/07 20:06:20 neelin 80 * Release of minc version 0.4 81 * 82 * Revision 1.1 1997/03/04 20:56:47 neelin 83 * Initial revision 84 * 85 @COPYRIGHT : 86 Copyright 1997 Peter Neelin, McConnell Brain Imaging Centre, 87 Montreal Neurological Institute, McGill University. 88 Permission to use, copy, modify, and distribute this 89 software and its documentation for any purpose and without 90 fee is hereby granted, provided that the above copyright 91 notice appear in all copies. The author and McGill University 92 make no representations about the suitability of this 93 software for any purpose. It is provided "as is" without 94 express or implied warranty. 95 ---------------------------------------------------------------------------- */ 96 97 #include <minc.h> 98 99 /* General constants */ 100 #define SECONDS_PER_MINUTE 60 101 #define MINUTES_PER_HOUR 60 102 #define SECONDS_PER_HOUR (MINUTES_PER_HOUR*SECONDS_PER_MINUTE) 103 #define HOURS_PER_DAY 24 104 #define SECONDS_PER_DAY (HOURS_PER_DAY*SECONDS_PER_HOUR) 105 #define MS_PER_SECOND 1000 106 #define COORDINATE_EPSILON (0.005) /* bert- relaxed from 1.0e-5 */ 107 108 /* Default value for ncopts */ 109 #define NCOPTS_DEFAULT NC_VERBOSE 110 111 /* MINC variable for dicom elements */ 112 #define DICOM_ROOT_VAR "dicom_groups" 113 114 /* Possible MRI dimensions */ 115 typedef enum { SLICE = 0, ECHO, TIME, PHASE, CHEM_SHIFT, MRI_NDIMS } Mri_Index; 116 117 extern const char *Mri_Names[MRI_NDIMS]; 118 119 /* World dimensions */ 120 typedef enum { XCOORD = 0, YCOORD, ZCOORD, WORLD_NDIMS } World_Index; 121 122 extern const char *World_Names[WORLD_NDIMS]; 123 124 /* Volume dimensions */ 125 typedef enum { VSLICE = 0, VROW, VCOLUMN, VOL_NDIMS } Volume_Index; 126 127 extern const char *Volume_Names[VOL_NDIMS]; 128 129 /* Orientations */ 130 typedef enum {TRANSVERSE = 0, SAGITTAL, CORONAL, NUM_ORIENTATIONS} Orientation; 131 132 /* Structure for general info about files */ 133 typedef struct { 134 int initialized; 135 double study_id; 136 int acq_id; /* Time of scan */ 137 int rec_num; 138 string_t image_type_string; 139 int nrows; 140 int ncolumns; 141 int default_index[MRI_NDIMS]; /* Index for dimensions with size == 1 */ 142 int cur_size[MRI_NDIMS]; /* Size of dimension across these files */ 143 int max_size[MRI_NDIMS]; /* Size of dimension across acquisition */ 144 int *indices[MRI_NDIMS]; /* List of indices found for each dimension. 145 Only allocated when size > 1 */ /* */ 146 int search_start[MRI_NDIMS]; /* Indices into lists for starting searches */ 147 double *coordinates[MRI_NDIMS]; /* Array indicating coordinate of each 148 index in indices array */ 149 double *widths[MRI_NDIMS]; /* Array indicating width of each index in 150 indices array */ 151 int image_index[MRI_NDIMS]; /* Mapping from MRI dim to output image dim */ 152 World_Index slice_world; 153 World_Index row_world; 154 World_Index column_world; 155 double step[WORLD_NDIMS]; 156 double start[WORLD_NDIMS]; 157 double dircos[WORLD_NDIMS][WORLD_NDIMS]; 158 nc_type datatype; /* netCDF (and therefore MINC) datatype */ 159 int is_signed; /* TRUE of 2's compliment data */ 160 double pixel_min; 161 double pixel_max; 162 string_t units; 163 double window_min; 164 double window_max; 165 int num_mosaic_rows; 166 int num_mosaic_cols; 167 int num_slices_in_file; 168 int sub_image_rows; 169 int sub_image_columns; 170 struct { 171 string_t name; 172 string_t identification; 173 string_t birth_date; 174 string_t age; 175 string_t sex; 176 string_t reg_date; 177 string_t reg_time; 178 double weight; 179 string_t position; /*added ilana*/ 180 } patient; 181 struct { 182 string_t start_time; 183 string_t modality; 184 string_t manufacturer; 185 string_t model; 186 double field_value; 187 string_t software_version; 188 string_t serial_no; 189 string_t calibration_date; 190 string_t calibration_time; 191 string_t institution; 192 string_t station_id; 193 string_t referring_physician; 194 string_t performing_physician; 195 string_t operator; 196 string_t procedure; 197 string_t study_id; 198 string_t acquisition_id; 199 } study; 200 struct { 201 string_t scan_seq; 202 string_t acquisition_time; /*added by ilana*/ 203 string_t image_time; /*added by ilana*/ 204 string_t series_time; /*added by ilana*/ 205 string_t protocol_name; 206 string_t series_description; /*added by ilana*/ 207 string_t receive_coil; 208 string_t transmit_coil; 209 double rep_time; 210 double slice_thickness; 211 double num_slices; 212 string_t slice_order; 213 double echo_time; 214 double echo_train_length; /*added by ilana*/ 215 double echo_number; 216 double inv_time; 217 double delay_in_TR; /*added by ilana*/ 218 double b_value; 219 double flip_angle; 220 double num_avg; 221 double num_dyn_scans; 222 double imaging_freq; 223 string_t imaged_nucl; 224 double win_center; 225 double win_width; 226 double num_phase_enc_steps; 227 double percent_sampling; 228 double percent_phase_fov; 229 double pixel_bandwidth; 230 string_t phase_enc_dir; 231 string_t mr_acq_type; 232 string_t image_type; 233 double sar; 234 string_t comments; 235 char *MrProt; // Siemens Numaris 4 specific 236 short dti; /* TRUE if we think this is DTI */ 237 } acq; 238 Acr_Group group_list; 239 } General_Info; 240 241 /* Structure for file-specific info */ 242 typedef struct { 243 int valid; 244 int bits_alloc; 245 int bits_stored; 246 int index[MRI_NDIMS]; 247 double pixel_max; 248 double pixel_min; 249 double slice_max; 250 double slice_min; 251 double window_max; 252 double window_min; 253 double coordinate[MRI_NDIMS]; 254 double width[MRI_NDIMS]; /* Sample width along each MRI dimension */ 255 double b_value; /* DTI b-value, if present */ 256 double grad_direction[WORLD_NDIMS]; /* DTI gradient direction */ 257 double b_matrix[6]; 258 } File_Info; 259 260 /* Structure for storing the actual image data */ 261 typedef struct { 262 unsigned short *data; 263 } Image_Data; 264 265 /* function definitions */ 266 extern int dicom_to_minc(int num_files, 267 const char **file_list, 268 const char *minc_file, 269 int clobber, 270 const char *file_prefix, 271 char **output_file_name); 272 extern Acr_Group read_std_dicom(const char *filename, int max_group); 273 extern Acr_Group read_numa4_dicom(const char *filename, int max_group); 274 extern int search_list(int value, const int *list_ptr, int list_length, 275 int start_index); 276 extern Acr_Group copy_spi_to_acr(Acr_Group group_list); 277 278 extern int is_siemens_mosaic(Acr_Group group_list); 279