Attachment 'mri.h'
Download 1 #ifndef MRI_H
2 #define MRI_H
3
4 #include "const.h"
5 #include "matrix.h"
6 /* remove unwanted warnings between hips_basic.h vs. volume_io/basic.h */
7 #undef ABS
8 #undef SIGN
9 #ifdef Darwin
10 // The result of not defining __MACTYPES__ is a scuba2 build error
11 // complaining about QT conflicting with MNI over the Point typedef.
12 // Notes from the file <mni installation>/include/volume_io/geom_structs.h:
13 /* Th 'Point' typedef is annoying to Mac OS users, since Point has been
14 * a basic type on Macs since the beginning. Testing __MACTYPES__ should
15 * work at least with the OS X codebase, I don't know if it existed in
16 * earlier versions of the MacTypes.h header.
17 */
18 #define __MACTYPES__
19 #endif
20 #include "volume_io.h"
21 #include "box.h"
22 #include "machine.h"
23
24 #define BUFTYPE unsigned char
25
26 #define SAMPLE_NEAREST 0
27 #define SAMPLE_TRILINEAR 1
28 #define SAMPLE_SINC 2
29 #define SAMPLE_CUBIC 3 /*E*/
30 #define SAMPLE_WEIGHTED 4
31
32 #define MRI_UCHAR 0
33 #define MRI_INT 1
34 #define MRI_LONG 2
35 #define MRI_FLOAT 3
36 #define MRI_SHORT 4
37 #define MRI_BITMAP 5
38 #define MRI_TENSOR 6
39
40 #define MAX_CMDS 1000
41
42 typedef struct
43 {
44 int x ;
45 int y ;
46 int z ;
47 int dx ;
48 int dy ;
49 int dz ;
50 } MRI_REGION ;
51
52 typedef struct
53 {
54 int width ;
55 int height ;
56 int depth ; /* # of slices */
57 int type ; /* data type for slices below */
58 int imnr0 ; /* starting image # */
59 int imnr1 ; /* ending image # */
60 int ptype ; /* not used */
61 float fov ;
62 float thick ;
63 float ps ;
64 float location ; /* not used */
65 float xsize ; /* size of a voxel in the x direction */
66 float ysize ; /* size of a voxel in the y direction */
67 float zsize ; /* size of a voxel in the z direction */
68 float xstart ; /* start x (in xsize units) */
69 float xend ; /* end x (in xsize units) */
70 float ystart ; /* start y (in ysize units) */
71 float yend ; /* end y (in ysize units) */
72 float zstart ; /* start z */
73 float zend ; /* end z */
74 float tr ; /* time to recovery */
75 float te ; /* time to echo */
76 float ti ; /* time to inversion */
77 char fname[STR_LEN] ;
78
79 float x_r, x_a, x_s; /* these are the RAS distances
80 across the whole volume */
81 float y_r, y_a, y_s; /* in x, y, and z */
82 float z_r, z_a, z_s; /* c_r, c_a, and c_s are the
83 center ras coordinates */
84 float c_r, c_a, c_s; /* ras_good_flag tells if
85 these coordinates are set */
86 int ras_good_flag; /* and accurate for the volume */
87
88 /* for bshorts and bfloats */
89 int brightness;
90 char subject_name[STRLEN];
91 MATRIX *register_mat;
92 char path_to_t1[STRLEN];
93 char fname_format[STRLEN];
94
95 /* for gdf volumes */
96 char gdf_image_stem[STRLEN];
97
98 /*
99 each slice is an array of rows (mri->height of them) each of which is
100 mri->width long.
101 */
102 BUFTYPE ***slices ;
103 int scale ;
104 char transform_fname[STR_LEN] ;
105 General_transform transform ; /* the next two are from this struct */
106 Transform *linear_transform ;
107 Transform *inverse_linear_transform ;
108 int free_transform ; /* are we responsible for freeing it? */
109 int nframes ; /* # of concatenated images */
110
111 /* these are used to handle boundary conditions (arrays of indices) */
112 int *xi ;
113 int *yi ;
114 int *zi ;
115 int yinvert ; /* for converting between MNC and coronal slices */
116 MRI_REGION roi ;
117 int dof ;
118 double mean ;
119 double flip_angle ; /* in radians */
120
121 void* tag_data; /* saved tag data */
122 int tag_data_size; /* size of saved tag data */
123 MATRIX *i_to_r__; /* cache */
124 MATRIX *r_to_i__;
125 char *cmdlines[MAX_CMDS] ;
126 int ncmds;
127 } MRI_IMAGE, MRI ;
128
129 MATRIX *MRIxfmCRS2XYZ(MRI *mri, int base);
130 MATRIX *MRIxfmCRS2XYZtkreg(MRI *mri);
131 MATRIX *MRItkReg2Native(MRI *ref, MRI *mov, MATRIX *R);
132 MATRIX *MRItkRegMtx(MRI *ref, MRI *mov, MATRIX *D);
133 MATRIX *MRIfixTkReg(MRI *mov, MATRIX *R);
134 MATRIX *MRIfsl2TkReg(MRI *ref, MRI *mov, MATRIX *FSLRegMat);
135 MATRIX *MRItkreg2FSL(MRI *ref, MRI *mov, MATRIX *tkRegMat);
136 MATRIX *MtxCRS1toCRS0(MATRIX *Q);
137
138 float MRIgetVoxVal(MRI *mri, int c, int r, int s, int f);
139 int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval);
140
141 char * MRIprecisionString(int PrecisionCode);
142 int MRIprecisionCode(char *PrecisionString);
143
144 int MRIareNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) ;
145 float MRIfindNearestNonzero(MRI *mri, int wsize, Real x0, Real y0, Real z0) ;
146 float MRIfindNearestNonzeroLocation(MRI *mri, int wsize,
147 Real xr, Real yr, Real zr,
148 int *pxv, int *pyv, int *pzv) ;
149 /* single pixel filtering */
150 float MRIvoxelMean(MRI *mri, int x, int y, int z, int wsize) ;
151 float MRIvoxelStd(MRI *mri, int x, int y, int z, float mean, int wsize) ;
152 float MRIvoxelZscore(MRI *mri, int x, int y, int z, int wsize) ;
153 float MRIvoxelDx(MRI *mri, int x, int y, int z) ;
154 float MRIvoxelDy(MRI *mri, int x, int y, int z) ;
155 float MRIvoxelDz(MRI *mri, int x, int y, int z) ;
156 float MRIvoxelGradient(MRI *mri, int x, int y, int z, float *pdx, float *pdy,
157 float *pdz) ;
158 float MRIvoxelDirection(MRI *mri, int x, int y, int z, int wsize) ;
159 float MRIvoxelGradientDir2ndDerivative(MRI *mri, int x0, int y0, int z0,
160 int wsize) ;
161 MRI * MRIgradientDir2ndDerivative(MRI *mri_src, MRI *mri_dst, int wsize) ;
162
163 /* use these constants for MRIreorder */
164 #define XDIM 1
165 #define YDIM 2
166 #define ZDIM 3
167 /* ch ov */
168 /*
169 MRI *MRIreorder(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim);
170 */
171
172 /* I/O functions */
173 /* ch ov */
174 /*
175 int MRIwrite(MRI *mri, char *fpref) ;
176 */
177 int MRIappend(MRI *mri, char *fpref) ;
178 int MRIwriteInfo(MRI *mri, char *fpref) ;
179 /* ch ov */
180 /*
181 MRI *MRIread(char *fpref) ;
182 MRI *MRIreadInfo(char *fpref) ;
183 */
184
185 /* memory allocation routines */
186 int MRIfree(MRI **pmri) ;
187 int MRIfreeFrames(MRI *mri, int start_frame) ;
188 MRI *MRIalloc(int width, int height, int depth, int type) ;
189 MRI *MRIallocSequence(int width, int height,int depth,int type,int nframes);
190 MRI *MRIallocHeader(int width, int height, int depth, int type) ;
191 int MRIallocIndices(MRI *mri) ;
192 int MRIsetResolution(MRI *mri, float xres, float yres, float zres) ;
193 int MRIsetTransform(MRI *mri, General_transform *transform) ;
194
195
196 /* correlation routines */
197 MRI *MRIxcorr(MRI *mri_ref, MRI *mri_in, MRI *mri_dst) ;
198 MRI *MRIxcorrWindow(MRI *mri_ref, MRI *mri_in,MRI *mri_dst,int window_size) ;
199 MRI *MRInxcorr(MRI *mri_ref, MRI *mri_in, MRI *mri_dst) ;
200 MRI *MRInxcorrWindow(MRI *mri_ref,MRI *mri_in,MRI *mri_dst,int window_size) ;
201 long MRIcorrelate(MRI *mri_ref, MRI *mri_in, int xoff, int yoff, int zoff) ;
202
203
204 int MRIpeak(MRI *mri, int *px, int *py, int *pz) ;
205 int MRIcopyHeader(MRI *mri_src, MRI *mri_dst) ;
206 int MRIcopyPulseParameters(MRI *mri_src, MRI *mri_dst) ;
207 MRI *MRIcopy(MRI *mri_src, MRI *mri_dst) ;
208 MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) ;
209 int MRIboundingBox(MRI *mri, int thresh, MRI_REGION *region) ;
210 int MRIfindApproximateSkullBoundingBox(MRI *mri, int thresh,
211 MRI_REGION *region) ;
212 int MRIboundingBoxNbhd(MRI *mri, int thresh, int wsize,MRI_REGION *region) ;
213
214 /* coordinate transforms */
215 MRI *MRItranslate(MRI *mri_src, MRI *mri_dst,
216 double dx, double dy, double dz) ;
217 MRI *MRIrotateX(MRI *mri_src, MRI *mri_dst, float x_angle) ;
218 MRI *MRIrotateY(MRI *mri_src, MRI *mri_dst, float y_angle) ;
219 MRI *MRIrotateZ(MRI *mri_src, MRI *mri_dst, float z_angle) ;
220 MRI *MRIrotate(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) ;
221 MRI *MRIscale(MRI *mri_src, MRI *mri_dst, float sx, float sy, float sz) ;
222 MRI *MRIaffine(MRI *mri_src, MRI *mri_dst, MATRIX *mA, MATRIX *mB) ;
223 MRI *MRIinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) ;
224 MRI *MRIlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *mA,
225 int InterpMethod);
226 MRI *MRIlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) ;
227 MRI *MRIapplyRASlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) ;
228 MRI *MRIapplyRASinverseLinearTransform(MRI *mri_src, MRI *mri_dst,
229 MATRIX *mA) ;
230 MRI *MRIapplyRASlinearTransformInterp(MRI *mri_src, MRI *mri_dst,
231 MATRIX *mA, int interpMethod) ;
232 MRI *MRIapplyRASinverseLinearTransformInterp(MRI *mri_src, MRI *mri_dst,
233 MATRIX *mA, int interpMethod) ;
234
235 int MRIinterpCode(char *InterpString);
236 char * MRIinterpString(int InterpCode);
237 MRI *MRIinterpolate(MRI *mri_src, MRI *mri_dst) ;
238 MRI *MRIconfThresh(MRI *mri_src, MRI *mri_probs, MRI *mri_classes,
239 MRI *mri_dst,float thresh, int min_target,int max_target);
240
241 /* debugging */
242 int MRIdump(MRI *mri, FILE *fp) ;
243 int MRIdumpBuffer(MRI *mri, FILE *fp) ;
244
245 /* arithmetic operations */
246 MRI *MRIsubtract(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
247 MRI *MRIabsdiff(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
248 MRI *MRIadd(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
249 MRI *MRIaverage(MRI *mri_src, int dof, MRI *mri_dst) ;
250 MRI *MRIdivide(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
251 MRI *MRImultiply(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
252 MRI *MRIscaleAndMultiply(MRI *mri1, float scale, MRI *mri2, MRI *mri_dst) ;
253 MRI *MRIabs(MRI *mri, MRI *mri_dst) ;
254 MRI *MRIscalarMul(MRI *mri_src, MRI *mri_dst, float scalar) ;
255 MRI *MRIscalarMulFrame(MRI *mri_src, MRI *mri_dst, float scalar, int frame) ;
256
257 #include "mrisegment.h"
258
259 /* filtering */
260 int MRIcpolvAllQuadrantsFilled(MRI *mri,
261 int x, int y, int z,int vertex,
262 int wsize) ;
263 MRI *MRIremoveIslands(MRI *mri_src, MRI*mri_dst, int wsize, int thresh) ;
264 MRI *MRIresegmentThinWMStrands(MRI *mri_src, MRI *mri_dst, int thickness);
265 MRI *MRIthickenThinWMStrands(MRI *mri_T1,
266 MRI *mri_src, MRI *mri_dst,
267 int thickness, int nsegments, float wm_hi) ;
268 MRI *MRIfindThinWMStrands(MRI *mri_src, MRI *mri_dst, int wsize);
269 MRI *MRIcentralPlaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst,
270 int wsize);
271 MRI *MRIplaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) ;
272 int MRIcpolvMaxWhiteAtVoxel(MRI *mri, int x, int y, int z, int wsize) ;
273 MRI *MRIpolvZscore(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) ;
274 MRI *MRIpolvNormalCurvature(MRI *mri_src, MRI *mri_dst, MRI *mri_polv,
275 int wsize) ;
276 MRI *MRIpolvMean(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) ;
277 MRI *MRIpolvMedian(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) ;
278 MRI *MRIpolvOrder(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize,
279 int thresh) ;
280 MRI *MRIpolvCount(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize,
281 int low_lim, int hi_lim) ;
282 MRI *MRIorderThreshold(MRI *mri_src, MRI *mri_dst, MRI *mri_order, int num) ;
283
284 MRI *MRIpolvMeanRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize,
285 MRI_REGION *region);
286 MRI *MRIpolvMedianRegion(MRI *mri_src, MRI *mri_dst,MRI *mri_polv,int wsize,
287 MRI_REGION *region);
288
289 MRI *MRIsobel(MRI *mri_src, MRI *mri_grad, MRI *mri_mag);
290 MRI *MRIxSobel(MRI *mri_src, MRI *mri_x, int frame) ;
291 MRI *MRIxSobelForAllTypes(MRI *mri_src, MRI *mri_x, int frame) ;
292 MRI *MRIySobel(MRI *mri_src, MRI *mri_y, int frame) ;
293 MRI *MRIySobelForAllTypes(MRI *mri_src, MRI *mri_y, int frame) ;
294 MRI *MRIzSobel(MRI *mri_src, MRI *mri_z, int frame) ;
295 MRI *MRIzSobelForAllTypes(MRI *mri_src, MRI *mri_z, int frame) ;
296 MRI *MRIsobelRegion(MRI *mri_src, MRI *mri_grad, int domag,
297 MRI_REGION *region);
298 MRI *MRIxSobelRegion(MRI *mri_src, MRI *mri_x, int frame,MRI_REGION *region);
299 MRI *MRIySobelRegion(MRI *mri_src, MRI *mri_y, int frame,MRI_REGION *region);
300 MRI *MRIzSobelRegion(MRI *mri_src, MRI *mri_z, int frame,MRI_REGION *region);
301
302 MRI *MRIreduce(MRI *mri_src, MRI *mri_dst) ;
303 MRI *MRIreduce2D(MRI *mri_src, MRI *mri_dst) ;
304 MRI *MRIreduceSlice(MRI *mri_src, MRI *mri_dst,
305 float *k, int len, int axis) ;
306 MRI *MRIreduceByte(MRI *mri_src, MRI *mri_dst) ;
307 MRI *MRIconvolve1dFloat(MRI *mri_src, MRI *mri_dst,
308 float *k, int len, int axis,
309 int src_frame, int dst_frame);
310 MRI *MRIconvolve1dShort(MRI *mri_src, MRI *mri_dst, float *k, int len,
311 int axis, int src_frame, int dst_frame) ;
312 MRI *MRIconvolve1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len,
313 int axis, int src_frame, int dst_frame) ;
314 MRI *MRIconvolve1d(MRI *mri_src, MRI *mri_dst, float *kernel,
315 int len, int axis, int src_frame, int dst_frame) ;
316 MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst,float *kernel,int len,int axis);
317 MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst,float *kernel,int len,
318 int axis);
319 MRI *MRIdiffuse(MRI *mri_src, MRI *mri_dst, double k,
320 int niter, int which, double slope) ;
321 MRI *MRIdiffuseCurvature(MRI *mri_src, MRI *mri_dst,
322 double A,int niter, double slope) ;
323 MRI *MRIdiffusePerona(MRI *mri_src, MRI *mri_dst,
324 double k, int niter,double slope);
325 MRI *MRIdirectionMap(MRI *mri_grad, MRI *mri_direction, int wsize);
326 MRI *MRIdirectionMapUchar(MRI *mri_grad, MRI *mri_direction, int wsize);
327 void MRIcalcCRASforSampledVolume(MRI *src, MRI *sampled,
328 Real *pr, Real *pa, Real *ps);
329 void MRIcalcCRASforExtractedVolume(MRI *src, MRI *dst,
330 int x0, int y0, int z0,
331 int x1, int y1, int z1,
332 Real *pr, Real *pa, Real *ps);
333 // 0 is the src extract position start
334 // 1 is the dst extracted region start
335 MRI *MRIsrcTransformedCentered(MRI *src, MRI *dst,
336 MATRIX *stod_voxtovox, int interp_method);
337 MRI *MRITransformedCenteredMatrix(MRI *src, MRI *orig_dst, MATRIX *m_L) ;
338
339 /* offset stuff */
340 MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction,
341 MRI *mri_dir);
342 MRI *MRIoffsetMagnitude(MRI *mri_src, MRI *mri_dst, int maxsteps) ;
343 MRI *MRIapplyOffset(MRI *mri_src, MRI *mri_dst, MRI *mri_offset) ;
344
345
346 MRI *MRIclone(MRI *mri_src, MRI *mri_dst) ; /* it just copies the
347 header info */
348 MRI *MRIcloneRoi(MRI *mri_src, MRI *mri_dst) ;
349 MRI *MRIcloneBySpace(MRI *mri_src, int nframes);
350 MRI *MRIthreshold(MRI *mri_src, MRI *mri_dst, float threshold) ;
351 MRI *MRIinvert(MRI *mri_src, MRI *mri_dst) ;
352 MRI *MRIinvertContrast(MRI *mri_src, MRI *mri_dst, float threshold) ;
353 MRI *MRIbinarize(MRI *mri_src, MRI *mri_dst, BUFTYPE threshold,
354 BUFTYPE low_val, BUFTYPE hi_val) ;
355 MRI *MRIthresholdRangeInto(MRI *mri_src, MRI *mri_dst,
356 BUFTYPE low_val, BUFTYPE hi_val) ;
357 int MRIprincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues,
358 double *means, BUFTYPE theshold) ;
359 int MRIcenterOfMass(MRI *mri,double *means, BUFTYPE threshold) ;
360 int MRIbinaryPrincipleComponents(MRI *mri, MATRIX *mEvectors,
361 float *evalues,
362 double *means, BUFTYPE theshold) ;
363 int MRIclear(MRI *mri_src) ;
364
365 /* these routines use trilinear interpolation */
366 MRI *MRIrotateX_I(MRI *mri_src, MRI *mri_dst, float x_angle) ;
367 MRI *MRIrotateY_I(MRI *mri_src, MRI *mri_dst, float y_angle) ;
368 MRI *MRIrotateZ_I(MRI *mri_src, MRI *mri_dst, float z_angle) ;
369 MRI *MRIrotate_I(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) ;
370
371 /* extraction routines */
372 MRI *MRIextract(MRI *mri_src, MRI *mri_dst,
373 int x0, int y0, int z0,
374 int dx, int dy, int dz) ;
375 MRI *MRIextractInto(MRI *mri_src, MRI *mri_dst,
376 int x0, int y0, int z0,
377 int dx, int dy, int dz,
378 int x1, int y1, int z1) ;
379 MRI *MRIextractIntoRegion(MRI *mri_src, MRI *mri_dst,
380 int x0, int y0, int z0,
381 MRI_REGION *region) ;
382
383 MRI *MRIextractRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *region) ;
384 MRI *MRIextractPolvPlane(MRI *mri_src, MRI *mri_dst, MRI *mri_polv,
385 int wsize, int x, int y, int z);
386 MRI *MRIextractCpolv(MRI *mri_src, MRI *mri_dst, MRI *mri_polv,
387 int wsize, int x, int y, int z);
388 MRI *MRIextractCpolvCoords(MRI *mri_src, int *px, int *py, int *pz,
389 MRI *mri_polv, int x, int y,int z,int wsize);
390 MRI *MRIextractValues(MRI *mri_src, MRI *mri_dst, float min_val,
391 float max_val) ;
392 MRI *MRIwmfilter(MRI *mri_src, MRI *mri_cpolv, MRI *mri_dst,
393 float nslope, float pslope) ;
394 MRI *MRIorder(MRI *mri_src, MRI *mri_dst, int wsize, float pct) ;
395 #if 1
396 MRI *MRIremoveHoles(MRI *mri_src, MRI*mri_dst, int wsize, float pct,
397 int use_all) ;
398 #else
399 MRI *MRIremoveHoles(MRI *mri_src, MRI*mri_dst, int wsize, float pct) ;
400 #endif
401
402 /* morphology */
403 MRI *MRImorph(MRI *mri_src, MRI *mri_dst, int which) ;
404 MRI *MRIerode(MRI *mri_src, MRI *mri_dst) ;
405 MRI *MRIerodeRegion(MRI *mri_src, MRI *mri_dst,int wsize,MRI_REGION *region);
406 MRI *MRIdilate(MRI *mri_src, MRI *mri_dst) ;
407 MRI *MRIdilateUchar(MRI *mri_src, MRI *mri_dst) ;
408 MRI *MRIopen(MRI *mri_src, MRI *mri_dst) ;
409 MRI *MRIclose(MRI *mri_src, MRI *mri_dst) ;
410 /* the following use 4 (or 6 in 3-D) connectivity */
411 MRI *MRIerode6(MRI *mri_src, MRI *mri_dst) ;
412 MRI *MRIdilate6(MRI *mri_src, MRI *mri_dst) ;
413 MRI *MRIopen6(MRI *mri_src, MRI *mri_dst) ;
414 MRI *MRIclose6(MRI *mri_src, MRI *mri_dst) ;
415 MRI *MRIunion(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
416 MRI *MRIintersect(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
417 MRI *MRIcomplement(MRI *mri_src, MRI *mri_dst) ;
418 MRI *MRIxor(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) ;
419 MRI *MRIand(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) ;
420 MRI *MRInot(MRI *mri_src, MRI *mri_dst) ;
421 MRI *MRIcomputeResidual(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) ;
422
423 /* filtering operations */
424 MRI *MRImodeFilter(MRI *mri_src, MRI *mri_dst, int niter) ;
425 MRI *MRImodeFilterWithControlPoints(MRI *mri_src,
426 MRI *mri_ctrl,
427 MRI *mri_dst,
428 int niter) ;
429 MRI *MRIthreshModeFilter(MRI *mri_src, MRI *mri_dst, int niter,float thresh);
430 MRI *MRIminmax(MRI *mri_src, MRI *mri_dst, MRI *mri_dir, int wsize) ;
431 MRI *MRIgaussian1d(float sigma, int max_len) ;
432 MRI *MRIconvolveGaussian(MRI *mri_src, MRI *mri_dst, MRI *mri_gaussian) ;
433 MRI *MRIgaussianSmooth(MRI *src, float std, int norm, MRI *targ);
434 MRI *MRIconvolveGaussianMeanAndStdByte(MRI *mri_src, MRI *mri_dst,
435 MRI *mri_gaussian) ;
436 MRI *MRIscaleMeanIntensities(MRI *mri_src, MRI *mri_ref, MRI *mri_dst) ;
437 MRI *MRImedian(MRI *mri_src, MRI *mri_dst, int wsize) ;
438 MRI *MRImean(MRI *mri_src, MRI *mri_dst, int wsize) ;
439 double MRImeanInLabel(MRI *mri_src, MRI *mri_labeled, int label) ;
440 MRI *MRImeanByte(MRI *mri_src, MRI *mri_dst, int wsize) ;
441 MRI *MRIstd(MRI *mri_src, MRI*mri_dst, MRI *mri_mean, int wsize) ;
442 MRI *MRIzScore(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std) ;
443
444 MRI *MRIdirectionMapRegion(MRI *mri_grad, MRI *mri_direction, int wsize,
445 MRI_REGION *region);
446 MRI *MRImeanRegion(MRI *mri_src, MRI *mri_dst, int wsize,MRI_REGION *region);
447 MRI *MRIstdRegion(MRI *mri_src, MRI*mri_dst, MRI *mri_mean, int wsize,
448 MRI_REGION *region) ;
449 MRI *MRIzScoreRegion(MRI *mri_src, MRI*mri_dst, MRI *mri_mean, MRI *mri_std,
450 MRI_REGION *region) ;
451
452 int MRIcheckSize(MRI *mri_src, MRI *mri_check, int width, int height,
453 int depth) ;
454 /* ch ov */
455 /*
456 MRI *MRIreadRaw(FILE *fp, int width, int height, int depth, int type) ;
457 */
458 int MRIinitHeader(MRI *mri) ;
459 int MRIreInitCache(MRI *mri); /* when header is modified,
460 you must call this function
461 to update cached info */
462 int MRIvoxelToWorld(MRI *mri, Real xv, Real yv, Real zv,
463 Real *xw, Real *yw, Real *zw) ;
464 int MRIworldToVoxel(MRI *mri, Real xw, Real yw, Real zw,
465 Real *pxv, Real *pyv, Real *pzv) ;
466 int MRIworldToVoxelIndex(MRI *mri, Real xw, Real yw, Real zw,
467 int *pxv, int *pyv, int *pzv) ;
468 MRI *MRItoTalairach(MRI *mri_src, MRI *mri_dst) ;
469 MRI *MRIfromTalairach(MRI *mri_src, MRI *mri_dst) ;
470 int MRIworldToTalairachVoxel(MRI *mri, Real xw, Real yw, Real zw,
471 Real *pxv, Real *pyv, Real *pzv) ;
472 int MRIvoxelToTalairachVoxel(MRI *mri, Real xv, Real yv, Real zv,
473 Real *pxt, Real *pyt, Real *pzt) ;
474 int MRIvoxelToVoxel(MRI *mri_src, MRI *mri_dst,
475 Real xv, Real yv, Real zv,
476 Real *pxt, Real *pyt, Real *pzt) ;
477 int MRItalairachVoxelToVoxel(MRI *mri, Real xt, Real yt, Real zt,
478 Real *pxv, Real *pyv, Real *pzv) ;
479 int MRItalairachVoxelToWorld(MRI *mri, Real xt, Real yt, Real zt,
480 Real *pxw, Real *pyw, Real *pzw) ;
481 int MRIvoxelToTalairach(MRI *mri, Real xv, Real yv, Real zv,
482 Real *pxt, Real *pyt, Real *pzt) ;
483 int MRItalairachToVoxel(MRI *mri, Real xt, Real yt, Real zt,
484 Real *pxv, Real *pyv, Real *pzv) ;
485
486 int MRItransformRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *src_region,
487 MRI_REGION *dst_region) ;
488 MRI *MRIextractArbitraryPlane(MRI *mri_src, MRI *mri_dst,
489 Real e1_x, Real e1_y, Real e1_z,
490 Real e2_x, Real e2_y, Real e2_z,
491 int x, int y, int z, int wsize);
492 MRI *MRIextractTalairachPlane(MRI *mri_src, MRI *mri_dst, int orientation,
493 int x, int y, int z, int size) ;
494 int MRIeraseTalairachPlane(MRI *mri, MRI *mri_mask, int orientation,
495 int x, int y, int z,int size,int fill_val);
496 int MRIeraseTalairachPlaneNew(MRI *mri, MRI *mri_mask, int orientation,
497 int x, int y, int z,int size,int fill_val);
498
499 MRI *MRIextractPlane(MRI *mri_src, MRI *mri_dst, int orientation,int where);
500 MRI *MRIfillPlane(MRI *mri_mask, MRI *mri_dst,
501 int orientation, int where, int fillval);
502 int MRIerasePlane(MRI *mri, float x0, float y0, float z0,
503 float dx, float dy, float dz, int fill_val);
504
505 int MRIeraseBorders(MRI *mri, int width) ;
506 int MRIindexNotInVolume(MRI *mri, Real col, Real row, Real slice) ;
507 int MRIsampleVolume(MRI *mri, Real x, Real y, Real z, Real *pval) ;
508 int MRIinterpolateIntoVolume(MRI *mri, Real x, Real y, Real z, Real val) ;
509 int MRIsampleVolumeSlice(MRI *mri, Real x, Real y, Real z, Real *pval,
510 int slice_direction) ;
511
512 int MRIsampleSeqVolume(MRI *mri, Real x, Real y, Real z, float *valvect,
513 int firstframe, int lastframe);
514
515 int MRIsampleVolumeType(MRI *mri, Real x, Real y, Real z, Real *pval,
516 int type) ;
517 int MRIsampleLabeledVolume(MRI *mri, Real x, Real y, Real z, Real *pval,
518 unsigned char ucharLabel);
519 int MRIsampleVolumeFrame(MRI *mri,Real x,Real y,Real z,int frame,Real *pval);
520 int MRIsampleVolumeFrameType(MRI *mri,Real x,Real y,Real z,
521 int frame, int interp_type,Real *pval);
522 int MRIsampleVolumeGradient(MRI *mri, Real x, Real y, Real z,
523 Real *pdx, Real *pdy, Real *pdz) ;
524 int MRIsampleVolumeGradientFrame(MRI *mri, Real x, Real y, Real z,
525 Real *pdx, Real *pdy, Real *pdz,
526 int frame) ;
527 int MRIsampleVolumeDerivative(MRI *mri, Real x, Real y, Real z,
528 Real dx, Real dy, Real dz, Real *pmag) ;
529 int MRIsampleVolumeDerivativeScale(MRI *mri, Real x, Real y, Real z,
530 Real dx, Real dy, Real dz, Real *pmag,
531 double sigma) ;
532 int MRIsampleVolumeDirectionScale(MRI *mri, Real x, Real y, Real z,
533 Real dx, Real dy, Real dz, Real *pmag,
534 double sigma) ;
535 float MRIsampleCardinalDerivative(MRI *mri, int x, int y, int z,
536 int xk, int yk, int zk) ;
537 float MRIsampleXDerivative(MRI *mri, int x, int y, int z, int dir) ;
538 float MRIsampleYDerivative(MRI *mri, int x, int y, int z, int dir) ;
539 float MRIsampleZDerivative(MRI *mri, int x, int y, int z, int dir) ;
540
541 /* resampling routines */
542 MRI *MRIupsample2(MRI *mri_src, MRI *mri_dst) ;
543 MRI *MRIdownsample2(MRI *mri_src, MRI *mri_dst) ;
544 MRI *MRIdownsample2LabeledVolume(MRI *mri_src, MRI *mri_dst) ;
545
546 /* surfaceRAS and voxel routines */
547 MATRIX *surfaceRASFromVoxel_(MRI *mri);
548 MATRIX *voxelFromSurfaceRAS_(MRI *mri);
549 MATRIX *surfaceRASFromRAS_(MRI *mri);
550 MATRIX *RASFromSurfaceRAS_(MRI *mri);
551
552 int MRIvoxelToSurfaceRAS(MRI *mri, Real xv, Real yv, Real zv,
553 Real *xs, Real *ys, Real *zs);
554 int MRIsurfaceRASToVoxel(MRI *mri, Real xr, Real yr, Real zr,
555 Real *xv, Real *yv, Real *zv);
556 int MRIRASToSurfaceRAS(MRI *mri, Real xr, Real yr, Real zr,
557 Real *xsr, Real *ysr, Real *zsr);
558 int MRIsurfaceRASToRAS(MRI *mri, Real xsr, Real ysr, Real zsr,
559 Real *xr, Real *yr, Real *zr);
560
561 #include "image.h"
562
563 IMAGE *MRItoImage(MRI *mri, IMAGE *I, int slice) ;
564 MRI *ImageToMRI(IMAGE *I);
565 IMAGE *MRItoImageView(MRI *mri, IMAGE *I, int slice, int view, int frame) ;
566
567 /* bitmap image access macros */
568 #define MRIset_bit(mri,x,y,z) MRIvox(mri,(x)/8,y,z) |= (0x001 << ((x)%8))
569 #define MRItest_bit(mri,x,y,z) (MRIvox(mri,(x)/8,(y),(z))&(0x001 << ((x)%8)))
570 #define MRIclear_bit(mri,x,y,z) MRIvox(mri,(x)/8,y,z) &= ~(0x001 << ((x)%8))
571
572 #define MRISvox(mri,x,y,z) (((short *)mri->slices[z][y])[x])
573 #define MRIFvox(mri,x,y,z) (((float *)(mri->slices[z][y]))[x])
574 #define MRIvox(mri,x,y,z) (((BUFTYPE *)mri->slices[z][y])[x])
575 #define MRISCvox(mri,x,y,z) (((signed char *)mri->slices[z][y])[x])
576 #define MRIIvox(mri,x,y,z) (((int *)mri->slices[z][y])[x])
577 #define MRILvox(mri,x,y,z) (((long32 *)mri->slices[z][y])[x])
578
579 #define MRISseq_vox(mri,x,y,z,n) (((short*)\
$^
mri->slices[z+(n)*mri->depth][y])[x])
580 #define MRISCseq_vox(mri,x,y,z,n) (((signed char*)\
$^
mri->slices[z+(n)*mri->depth][y])[x])
581 #define MRIFseq_vox(mri,x,y,z,n) (((float*)\
$^
(mri->slices[z+((n)*mri->depth)][y]))[x])
582 #define MRIseq_vox(mri,x,y,z,n) (((BUFTYPE *)\
$^
mri->slices[z+(n)*mri->depth][y])[x])
583 #define MRIIseq_vox(mri,x,y,z,n) (((int *)\
$^
mri->slices[z+(n)*mri->depth][y])[x])
584 #define MRILseq_vox(mri,x,y,z,n) (((long32 *)\
$^
mri->slices[z+(n)*mri->depth][y])[x])
585
586 #define MRI_HEIGHT 0
587 #define MRI_WIDTH 1
588 #define MRI_DEPTH 2
589
590 #define MRI_UNDEFINED -1
591 #define MRI_CORONAL 0
592 #define MRI_SAGITTAL 1
593 #define MRI_HORIZONTAL 2
594 #define MRI_AXIAL MRI_HORIZONTAL
595
596 /* vertices of an icosahedron (sp?), used by all POLV functions */
597 #define NVERTICES 22
598 extern float ic_x_vertices[] ;
599 extern float ic_y_vertices[] ;
600 extern float ic_z_vertices[] ;
601
602 #include "label.h"
603 #include "histo.h"
604
605 #define MRI_GZIPPED -2
606 #define MRI_VOLUME_TYPE_UNKNOWN -1
607 #define MRI_CORONAL_SLICE_DIRECTORY 0
608 #define MRI_MINC_FILE 1
609 #define MRI_ANALYZE_FILE 2
610 #define MRI_MGH_FILE 3
611 #define GENESIS_FILE 4
612 #define GE_LX_FILE 5
613 #define SIEMENS_FILE 6
614 #define BRIK_FILE 7
615 #define BSHORT_FILE 8
616 #define BFLOAT_FILE 9
617 #define SDT_FILE 10
618 #define OTL_FILE 11
619 #define GDF_FILE 12
620 #define RAW_FILE 13
621 #define SIGNA_FILE 14
622 #define DICOM_FILE 15
623 #define MRI_ANALYZE4D_FILE 16
624 #define SIEMENS_DICOM_FILE 17
625 #define BRUKER_FILE 18
626 #define XIMG_FILE 19
627 #define NIFTI1_FILE 20 // NIfTI-1 .img + .hdr
628 #define IMAGE_FILE 21
629 #define MRI_GCA_FILE 22
630 #define BHDR 23 // for bshort or bfloat
631 #define NII_FILE 24 // NIfTI-1 .nii (single file)
632 #define MRI_CURV_FILE 25 // surface curv format
633
634 int MRImatch(MRI *mri1, MRI *mri2) ;
635 int MRInonzeroValRange(MRI *mri, float *pmin, float *pmax) ;
636 int MRIvalRange(MRI *mri, float *pmin, float *pmax) ;
637 int MRIvalRangeFrame(MRI *mri, float *pmin, float *pmax, int frame) ;
638 MRI *MRIvalScale(MRI *mri_src, MRI *mri_dst, float fmin, float fmax) ;
639 HISTOGRAM *MRIhistogram(MRI *mri, int nbins) ;
640 HISTOGRAM *MRIhistogramLabel(MRI *mri, MRI *mri_labeled,
641 int label, int nbins);
642 HISTOGRAM *MRIhistogramLabelRegion(MRI *mri,
643 MRI *mri_labeled,
644 MRI_REGION *region,
645 int label, int nbins);
646 MRI *MRIhistoEqualize(MRI *mri_src, MRI *mri_template, MRI *mri_dst,
647 int low, int high) ;
648 MRI *MRIapplyHistogram(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo) ;
649 MRI *MRIcrunch(MRI *mri_src, MRI *mri_dst) ;
650 HISTOGRAM *MRIgetEqualizeHisto(MRI *mri, HISTOGRAM *histo_eq, int low,
651 int high, int norm) ;
652
653 /* these are adaptive (i.e. only operate on a subregion of the whole image */
654 MRI_REGION *MRIclipRegion(MRI *mri, MRI_REGION *reg_src, MRI_REGION *reg_clip);
655 int MRIvalRangeRegion(MRI *mri, float *pmin, float *pmax,
656 MRI_REGION *region) ;
657 HISTOGRAM *MRIhistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo,
658 MRI_REGION *region) ;
659 HISTOGRAM *MRIhistogramLabelStruct(MRI *mri, int nbins, HISTOGRAM *histo,
660 LABEL *label) ;
661 MRI *MRIhistoEqualizeRegion(MRI *mri_src, MRI *mri_dst, int low,
662 MRI_REGION *region) ;
663 MRI *MRIapplyHistogramToRegion(MRI *mri_src, MRI *mri_dst,
664 HISTOGRAM *histo, MRI_REGION *region) ;
665 HISTOGRAM *MRIgetEqualizeHistoRegion(MRI *mri, HISTOGRAM *histo_eq, int low,
666 MRI_REGION *region, int norm) ;
667 int MRIfileType(char *fname) ;
668 int MRIunpackFileName(char *inFname, int *pframe, int *ptype,
669 char *outFname) ;
670 Volume MRItoVolume(MRI *mri) ;
671 MRI *MRIfromVolume(Volume volume, int start_frame, int end_frame) ;
672 int MRIisValid(MRI *mri) ;
673 MRI *MRIflipByteOrder(MRI *mri_src, MRI *mri_dst) ;
674
675 MRI *MRIregionGrow(MRI *mri_src, MRI *mri_distance,
676 float x0, float y0, float z0, int niter) ;
677 MRI *MRIextractInterior(MRI *mri_src, MRI *mri_distance, MRI *mri_dst);
678 MRI *MRIbuildDistanceMap(MRI *mri_src, MRI *mri_distance,
679 float x0, float y0, float z0, float r) ;
680 MRI *MRIupdateDistanceMap(MRI *mri_distance) ;
681 int MRIvalueFill(MRI *mri, float value);
682 MRI *MRIfill(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y,
683 int seed_z, int threshold, int fill_val, int max_count) ;
684 MRI *MRIfillFG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y,
685 int seed_z, int threshold, int fill_val, int *npix) ;
686 MRI *MRIfillBG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y,
687 int seed_z, int threshold, int fill_val, int *npix) ;
688
689 int MRIneighbors3x3(MRI *mri, int x, int y, int z, int val) ;
690 int MRIneighbors(MRI *mri, int x, int y, int z, int val) ;
691 int MRIneighborsOn(MRI *mri, int x0, int y0, int z0, int min_val) ;
692 int MRIneighborsOff(MRI *mri, int x0, int y0, int z0, int min_val) ;
693 int MRIneighborsOn3x3(MRI *mri, int x0, int y0, int z0, int min_val) ;
694 int MRIneighborsOff3x3(MRI *mri, int x0, int y0, int z0, int min_val) ;
695 int MRIlabelsInNbhd(MRI *mri, int x, int y, int z, int whalf, int label) ;
696
697 int MRIvol2Vol(MRI *src, MRI *targ, MATRIX *Vt2s,
698 int InterpCode, float param);
699
700 MRI *MRIresampleFill(MRI *src, MRI *template_vol,
701 int resample_type, float fill_val) ;
702 MRI *MRIreplaceValues(MRI *mri_src, MRI *mri_dst,
703 float in_val, float out_val) ;
704 MRI *MRIreplaceValuesUchar(MRI *mri_src, MRI *mri_dst,
705 BUFTYPE in_val, BUFTYPE out_val) ;
706 MRI *MRImask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask,
707 float out_val) ;
708 MRI *MRImaskInvert(MRI *mask, MRI *outmask);
709 int MRInMask(MRI *mask);
710
711 MRI *MRImeanMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst,
712 int mask, int wsize) ;
713 MRI *MRIthresholdMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst,
714 float mask_threshold, float out_val) ;
715
716 /* constants used in mri_dir of MRIoffsetDirection and for MRIminmax filter */
717 #define OFFSET_NEGATIVE_GRADIENT_DIRECTION 0
718 #define OFFSET_GRADIENT_DIRECTION 1
719 #define OFFSET_ZERO 2
720
721 /* anything below this is not white matter */
722 #define WM_MIN_VAL 5
723 #define MIN_WM_VAL WM_MIN_VAL
724 #define WM_EDITED_ON_VAL 255
725 #define WM_EDITED_OFF_VAL 1
726
727 MRI *MRIreduceMeanAndStdByte(MRI *mri_src, MRI *mri_dst) ;
728 MRI *MRIstdsToVariances(MRI *mri_std, MRI *mri_var, int source_frame) ;
729 MRI *MRIvariancesToStds(MRI *mri_var, MRI *mri_std, int dst_frame) ;
730 MRI *MRIconcatenateFrames(MRI *mri_frame1, MRI *mri_frame2, MRI *mri_dst);
731 MRI *MRIcopyFrame(MRI *mri_src, MRI *mri_dst, int src_frame, int dst_frame) ;
732 double MRImeanFrame(MRI *mri, int frame) ;
733
734 int MRIcountPlanarAboveThreshold(MRI *mri_src, int vertex, int x, int y,
735 int z, int wsize, int lo_lim, int hi_lim);
736 int MRIcountCpolvAtVoxel(MRI *mri_src, int x, int y, int z, int wsize,
737 int *pnum, int label_to_check) ;
738
739 MRI *MRIhistoSegment(MRI *mri_src, MRI *mri_labeled, int wm_low, int wm_hi,
740 int gray_hi, int wsize, float sigma) ;
741 MRI *MRIhistoSegmentVoxel(MRI *mri_src, MRI *mri_labeled, int wm_low,
742 int wm_hi, int gray_hi, int wsize, int x, int y,
743 int z, HISTOGRAM *histo, HISTOGRAM *hsmooth,
744 float sigma) ;
745 MRI *MRIcpolvSmooth(MRI *mri_orig,MRI *mri_src, MRI *mri_dst, int wsize,
746 int low_val, int hi_val, int niter) ;
747 MRI *MRIextractVertexCoords(MRI *mri_src, int *px, int *py, int *pz,
748 int vertex, int x, int y,int z, int wsize) ;
749
750 MRI *MRIextractVertexPlane(MRI *mri_src, MRI *mri_dst, int vertex, int x,
751 int y, int z, int wsize) ;
752 int MRIwhiteInPlane(MRI *mri_src, int x, int y, int z, int vertex, int wsize);
753 int MRIneighborhoodPlanarDirection(MRI *mri_src, int xv, int yv, int zv,
754 int nsize, int wsize) ;
755 int MRIneighborhoodCpolv(MRI *mri_src, int xv, int yv, int zv,int nsize,
756 int wsize, int *pnum_white) ;
757 int MRIneighborsInWindow(MRI *mri, int x, int y, int z, int wsize, int val) ;
758 int MRIneighborhoodBlackCpolv(MRI *mri_src, int xv, int yv, int zv,
759 int nsize, int wsize, int *pnum_black) ;
760
761 MRI *MRIorderSegment(MRI *mri_src, MRI *mri_labeled, float thresh, int wsize);
762 MRI *MRIthresholdLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst,
763 int wm_low) ;
764 MRI *MRIintensitySegmentation(MRI *mri_src, MRI *mri_labeled,
765 float wm_low, float wm_hi, float gray_hi) ;
766 MRI *MRImeanLabel(MRI *mri_src, MRI *mri_label, MRI*mri_dst, int wsize) ;
767 int MRIvoxelsInLabel(MRI *mri, int label) ;
768 int MRItotalVoxelsOn(MRI *mri, int thresh) ;
769 int MRIcopyLabel(MRI *mri_src, MRI *mri_dst, int val) ;
770 int MRIcopyLabeledVoxels(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst,
771 int label) ;
772 MRI *MRIcpolvVote(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wsize,
773 int niter, int use_all) ;
774 MRI *MRIcpolvThreshold(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst,
775 int wm_low, int gray_hi,int wsize) ;
776 MRI *MRImaskLabels(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) ;
777
778
779 MRI *MRIwmfilterMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize,
780 float pct, int onoff) ;
781 int MRIcountCpolvAtVoxel(MRI *mri_src, int x, int y, int z, int wsize,
782 int *pnum, int label_to_check) ;
783 int MRIcountCpolvOnAtVoxel(MRI *mri_src, int x, int y, int z, int wsize,
784 int *pnum) ;
785 MRI *MRIcentralPlaneOfLeastVarianceNormalMarked(MRI *mri_src, MRI *mri_mask,
786 MRI *mri_dst, int wsize) ;
787 int MRIcountCpolvOffAtVoxel(MRI *mri_src,int x, int y, int z, int wsize,
788 int *pnum) ;
789 int MRIcentralPlaneOfLeastVarianceNormalVoxel(MRI *mri_src, int wsize,
790 int x, int y, int z) ;
791 int MRIvertexToVector(int vertex, float *pdx, float *pdy, float *pdz) ;
792 int MRIcpolvMedianCurveVoxel(MRI *mri, MRI *mri_labeled, int x0, int y0,
793 int z0, int wsize, float len, float gray_hi,
794 float wm_low) ;
795 float MRIcpolvMedianAtVoxel(MRI *mri_src, int vertex,
796 float x, float y, float z, int wsize);
797 MRI *MRIcpolvMedianCurveSegment(MRI *mri,MRI *mri_labeled, MRI *mri_dst,
798 int wsize,float len, float gray_hi,
799 float wm_low);
800
801 MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) ;
802 int MRIborderClassifyVoxel(MRI *mri_src, MRI *mri_labeled, int wsize, int x,
803 int y, int z, float *ppw, float *ppg) ;
804 int MRIreclassifyBorder(MRI *mri_src, MRI *mri_labeled, MRI *mri_border,
805 MRI *mri_dst, int wsize) ;
806
807 int MRIclassifyAmbiguous(MRI *mri_src, MRI *mri_labeled, MRI *mri_border,
808 MRI *mri_dst, int wsize) ;
809
810 MRI *MRIremoveBrightStuff(MRI *mri_src, MRI *mri_dst, int threshold) ;
811 int MRIreclassify(MRI *mri_src, MRI *mri_labeled,
812 MRI *mri_dst, float wm_low, float gray_hi, int wsize) ;
813
814
815 MRI *MRImaskThreshold(MRI *mri_src, MRI *mri_mask, MRI *mri_dst,
816 float threshold, int out_label) ;
817 int MRIgrowLabel(MRI *mri, MRI *mri_bg, int in_label, int out_label) ;
818 int MRIturnOnFG(MRI *mri, MRI *mri_fg, MRI *mri_bg) ;
819 int MRIturnOffBG(MRI *mri, MRI *mri_bg) ;
820 /* mriprob.c */
821 MRI *MRIcomputeConditionalProbabilities(MRI *mri_T1, MRI *mri_mean,
822 MRI *mri_std, MRI *mri_dst) ;
823 MRI *MRIapplyBayesLaw(MRI *mri_priors, MRI *mri_p1, MRI *mri_p2,MRI *mri_dst);
824 MRI *MRIprobabilityThresholdNeighborhoodOff(MRI *mri_src, MRI *mri_prob,
825 MRI *mri_dst, float threshold,
826 int nsize) ;
827 MRI *MRIprobabilityThresholdNeighborhoodOn(MRI *mri_src, MRI *mri_prob,
828 MRI *mri_dst, float threshold,
829 int nsize, int out_label) ;
830 MRI *MRIprobabilityThreshold(MRI *mri_src, MRI *mri_prob, MRI *mri_dst,
831 float threshold, int out_label) ;
832 MRI *MRIdilateLabel(MRI *mri_src, MRI *mri_dst, int label, int niter) ;
833 MRI *MRIdilateLabelUchar(MRI *mri_src, MRI *mri_dst, int label, int niter) ;
834 MRI *MRIdilateThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label,
835 int niter, int thresh) ;
836 MRI *MRIdilateInvThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst,
837 int label,
838 int niter, int thresh) ;
839 MRI *MRIsoapBubbleLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst,
840 int label,
841 int niter);
842 MRI *MRIsetLabelValues(MRI *mri_src, MRI *mri_label, MRI *mri_dst,
843 int label, float val);
844 int MRIwriteImageViews(MRI *mri, char *base_name, int target_size) ;
845 int MRIsetValues(MRI *mri, float val) ;
846 MRI *MRIwindow(MRI *mri_src, MRI *mri_dst, int which, float x0, float y0,
847 float z0, float parm) ;
848 int MRIcomputeClassStatistics(MRI *mri_T1, MRI *mri_labeled,
849 float gray_low, float gray_hi,
850 float *pmean_wm, float *psigma_wm,
851 float *pmean_gm, float *psigma_gm) ;
852
853 #define WINDOW_GAUSSIAN 0
854 #define WINDOW_HAMMING 1
855 #define WINDOW_HANNING 2
856
857 #define MRI_NOT_WHITE 1
858 #define MRI_AMBIGUOUS 128
859 #define MRI_WHITE 255
860
861 #define MRI_LEFT_HEMISPHERE 255
862 #define MRI_RIGHT_HEMISPHERE 127
863 #define MRI_RIGHT_HEMISPHERE2 80
864
865
866 /* STATS volumes have 2 images each */
867 #define TRI_HI_PRIORS 0
868 #define TRI_HI_STATS 1
869 #define TRI_LOW_PRIORS 3
870 #define TRI_LOW_STATS 4
871 #define TRI_OFF_STATS 6
872
873
874 #define REMOVE_1D 2
875 #define REMOVE_WRONG_DIR 3
876
877 #define BASAL_GANGLIA_FILL 50
878 #define MAX_WM_VAL (THICKEN_FILL-1)
879 #define WM_MAX_VAL MAX_WM_VAL
880 #define THICKEN_FILL 200
881 #define NBHD_FILL 210
882 #define VENTRICLE_FILL 220
883 #define DIAGONAL_FILL 230
884 #define DEGENERATE_FILL 240
885 #define OFFSET_FILTER_FILL 245
886 #define AUTO_FILL 250
887 #define PRETESS_FILL 215
888
889 MRI *MRIchangeType(MRI *src, int dest_type, float f_low,
890 float f_high, int no_scale_option_flag);
891 MRI *MRISeqchangeType(MRI *vol, int dest_type, float f_low,
892 float f_high, int no_scale_option_flag);
893
894 MRI *MRIresample(MRI *src, MRI *template_vol, int resample_type);
895 MATRIX *MRIgetResampleMatrix(MRI *src, MRI *template_vol);
896 int MRIlimits(MRI *mri, float *min, float *max);
897 int MRIprintStats(MRI *mri, FILE *stream);
898 int MRIstats(MRI *mri, float *min, float *max, int *n_voxels,
899 float *mean, float *std);
900
901 float MRIvolumeDeterminant(MRI *mri);
902
903 int mriio_command_line(int argc, char *argv[]);
904 int mriio_set_subject_name(char *name);
905 int MRIgetVolumeName(char *string, char *name_only);
906 MRI *MRIread(char *fname);
907 MRI *MRIreadEx(char *fname, int nthframe);
908 MRI *MRIreadType(char *fname, int type);
909 MRI *MRIreadInfo(char *fname);
910 MRI *MRIreadHeader(char *fname, int type);
911 int GetSPMStartFrame(void);
912 int MRIwrite(MRI *mri, char *fname);
913 int MRIwriteFrame(MRI *mri, char *fname, int frame) ;
914 int MRIwriteType(MRI *mri, char *fname, int type);
915 int MRIwriteAnyFormat(MRI *mri, char *fileid, char *fmt,
916 int mriframe, MRIS *surf);
917 MRI *MRIreadRaw(FILE *fp, int width, int height, int depth, int type);
918 MRI *MRIreorder(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim);
919 MRI *MRIsmoothParcellation(MRI *mri, int smooth_parcellation_count);
920 MRI *MRIreadGeRoi(char *fname, int n_slices);
921
922 int decompose_b_fname(char *fname_passed, char *directory, char *stem);
923
924 #define READ_OTL_READ_VOLUME_FLAG 0x01
925 #define READ_OTL_FILL_FLAG 0x02
926 #define READ_OTL_TRANSLATE_LABELS_FLAG 0x04
927 #define READ_OTL_ZERO_OUTLINES_FLAG 0x08
928 MRI *MRIreadOtl(char *fname, int width, int height, int slices,
929 char *color_file_name, int flags);
930
931 MATRIX *extract_i_to_r(MRI *mri);
932 int apply_i_to_r(MRI *mri, MATRIX *m);
933
934 int stuff_four_by_four(MATRIX *m,
935 float m11, float m12, float m13, float m14,
936 float m21, float m22, float m23, float m24,
937 float m31, float m32, float m33, float m34,
938 float m41, float m42, float m43, float m44);
939
940 MATRIX *extract_r_to_i(MRI *mri) ;
941 #define MRIgetVoxelToRasXform extract_i_to_r
942 #define MRIgetRasToVoxelXform extract_r_to_i
943 int MRIsetVoxelToRasXform(MRI *mri, MATRIX *m_vox2ras) ;
944 MATRIX *MRIvoxelXformToRasXform(MRI *mri_src, MRI *mri_dst,
945 MATRIX *m_voxel_xform, MATRIX *m_ras_xform);
946 MATRIX *MRIrasXformToVoxelXform(MRI *mri_src, MRI *mri_dst,
947 MATRIX *m_ras_xform, MATRIX *m_voxel_xform);
948
949
950 int MRIsincSampleVolume(MRI *mri, Real x, Real y, Real z, int hw, Real *pval);
951 int MRIcubicSampleVolume(MRI *mri, Real x, Real y, Real z, Real *pval); /*E*/
952 MRI *MRIsincTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int hw);
953 int MRIlabelOverlap(MRI *mri1, MRI *mri2, int label) ;
954 int MRIeraseBorderPlanes(MRI *mri) ;
955
956 MRI *MRIlog10(MRI *inmri, MRI *outmri, int negflag);
957 MRI *MRIrandn(int ncols, int nrows, int nslices, int nframes,
958 float avg, float stddev, MRI *mri);
959 MRI *MRIrande(int ncols, int nrows, int nslices, int nframes,
960 float avg, int order, MRI *mri);
961 MRI *MRIdrand48(int ncols, int nrows, int nslices, int nframes,
962 float min, float max, MRI *mri);
963 MRI *MRIsampleCDF(int ncols, int nrows, int nslices, int nframes,
964 double *xCDF, double *CDF, int nCDF, MRI *mri);
965 MRI *MRIconst(int ncols, int nrows, int nslices, int nframes,
966 float val, MRI *mri);
967 int MRInormalizeSequence(MRI *mri, float target) ;
968
969 int setDirectionCosine(MRI *mri, int orientation);
970 int getSliceDirection(MRI *mri);
971 int mriOKforSurface(MRI *mri); // check whether the volume is conformed or not
972 int mriConformed(MRI *mri) ;
973 void setMRIforSurface(MRI *mri); // set c_(r,a,s) = 0 for a conformed volume
974 MRI *MRIremoveNaNs(MRI *mri_src, MRI *mri_dst) ;
975 MRI *MRImakePositive(MRI *mri_src, MRI *mri_dst);
976 MRI *MRIeraseNegative(MRI *mri_src, MRI *mri_dst) ;
977
978 MRI *MRImarkLabelBorderVoxels(MRI *mri_src, MRI *mri_dst,
979 int label, int mark, int six_connected) ;
980 int MRIcomputeLabelNbhd(MRI *mri_labels, MRI *mri_vals,
981 int x, int y, int z,
982 int *label_counts, float *label_means,
983 int whalf, int max_labels) ;
984 float MRIvoxelsInLabelWithPartialVolumeEffects(MRI *mri, MRI *mri_vals,
985 int label) ;
986 MRI *MRImakeDensityMap(MRI *mri, MRI *mri_vals, int label, MRI *mri_dst) ;
987 int MRIcropBoundingBox(MRI *mri, MRI_REGION *box) ;
988 MRI *MRIapplyBiasCorrection(MRI *mri_in, MRI *mri_bias, MRI *mri_out) ;
989 MRI *MRIapplyBiasCorrectionSameGeometry(MRI *mri_in, MRI *mri_bias,
990 MRI *mri_out, float target_val) ;
991 MATRIX *MRIgetVoxelToVoxelXform(MRI *mri_src, MRI *mri_dst) ;
992
993 /* extract the RASToVoxeMatrix from an MRI */
994 MATRIX *GetSurfaceRASToVoxelMatrix(MRI *mri);
995
996 /* Zero-padding for 3d analyze (ie, spm) format */
997 #ifdef _MRIIO_SRC
998 int N_Zero_Pad_Input = -1;
999 int N_Zero_Pad_Output = -1;
1000 #else
1001 extern int N_Zero_Pad_Input;
1002 extern int N_Zero_Pad_Output;
1003 #endif
1004
1005 float MRIfovCol(MRI *mri);
1006 int MRIdircosToOrientationString(MRI *mri, char *ostr);
1007 int MRIorientationStringToDircos(MRI *mri, char *ostr);
1008 char *MRIcheckOrientationString(char *ostr);
1009 char *MRIsliceDirectionName(MRI *mri);
1010 MRI *MRIreverseSliceOrder(MRI *invol, MRI *outvol);
1011
1012 /* different modes for distance transform - signed
1013 (<0 in interior) unsigned from border, or
1014 just outside (interior is 0) */
1015 #define DTRANS_MODE_SIGNED 1
1016 #define DTRANS_MODE_UNSIGNED 2
1017 #define DTRANS_MODE_OUTSIDE 3
1018 MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist,
1019 int label, float max_dist, int mode);
1020 int MRIaddCommandLine(MRI *mri, char *cmdline) ;
1021 int MRIcopyVolGeomToMRI(MRI *mri, VOL_GEOM *vg) ;
1022 MRI *MRInonMaxSuppress(MRI *mri_src, MRI *mri_sup,
1023 float thresh, int thresh_dir) ;
1024 MRI *MRIextractRegionAndPad(MRI *mri_src, MRI *mri_dst,
1025 MRI_REGION *region, int pad) ;
1026 MRI *MRIsetValuesOutsideRegion(MRI *mri_src,
1027 MRI_REGION *region,
1028 MRI *mri_dst,
1029 float val) ;
1030 int MRIcountNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) ;
1031
1032 #endif
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2009-01-26 22:35:32, 12.9 KB) [[attachment:fio.c]]
- [get | view] (2009-01-26 22:35:32, 1.3 KB) [[attachment:fio.h]]
- [get | view] (2009-01-26 22:35:32, 5.9 KB) [[attachment:load_mgh.m]]
- [get | view] (2009-01-26 22:35:32, 9.3 KB) [[attachment:matrix.h]]
- [get | view] (2009-01-26 22:35:32, 390.2 KB) [[attachment:mri.c]]
- [get | view] (2009-01-26 22:35:32, 48.5 KB) [[attachment:mri.h]]
- [get | view] (2009-01-26 22:35:32, 94.4 KB) [[attachment:mri_convert.c]]
- [get | view] (2009-01-26 22:35:32, 14.1 KB) [[attachment:mri_info.c]]
- [get | view] (2009-01-26 22:35:32, 395.4 KB) [[attachment:mriio.c]]
- [get | view] (2009-01-26 22:35:32, 2.4 KB) [[attachment:save_mgh.m]]
- [get | view] (2009-01-26 22:35:32, 2.2 KB) [[attachment:tags.c]]
- [get | view] (2009-01-26 22:35:32, 0.9 KB) [[attachment:tags.h]]
You are not allowed to attach a file to this page.