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*)\
580 mri->slices[z+(n)*mri->depth][y])[x])
581 #define MRISCseq_vox(mri,x,y,z,n) (((signed char*)\
582 mri->slices[z+(n)*mri->depth][y])[x])
583 #define MRIFseq_vox(mri,x,y,z,n) (((float*)\
584 (mri->slices[z+((n)*mri->depth)][y]))[x])
585 #define MRIseq_vox(mri,x,y,z,n) (((BUFTYPE *)\
586 mri->slices[z+(n)*mri->depth][y])[x])
587 #define MRIIseq_vox(mri,x,y,z,n) (((int *)\
588 mri->slices[z+(n)*mri->depth][y])[x])
589 #define MRILseq_vox(mri,x,y,z,n) (((long32 *)\
590 mri->slices[z+(n)*mri->depth][y])[x])
591
592 #define MRI_HEIGHT 0
593 #define MRI_WIDTH 1
594 #define MRI_DEPTH 2
595
596 #define MRI_UNDEFINED -1
597 #define MRI_CORONAL 0
598 #define MRI_SAGITTAL 1
599 #define MRI_HORIZONTAL 2
600 #define MRI_AXIAL MRI_HORIZONTAL
601
602 /* vertices of an icosahedron (sp?), used by all POLV functions */
603 #define NVERTICES 22
604 extern float ic_x_vertices[] ;
605 extern float ic_y_vertices[] ;
606 extern float ic_z_vertices[] ;
607
608 #include "label.h"
609 #include "histo.h"
610
611 #define MRI_GZIPPED -2
612 #define MRI_VOLUME_TYPE_UNKNOWN -1
613 #define MRI_CORONAL_SLICE_DIRECTORY 0
614 #define MRI_MINC_FILE 1
615 #define MRI_ANALYZE_FILE 2
616 #define MRI_MGH_FILE 3
617 #define GENESIS_FILE 4
618 #define GE_LX_FILE 5
619 #define SIEMENS_FILE 6
620 #define BRIK_FILE 7
621 #define BSHORT_FILE 8
622 #define BFLOAT_FILE 9
623 #define SDT_FILE 10
624 #define OTL_FILE 11
625 #define GDF_FILE 12
626 #define RAW_FILE 13
627 #define SIGNA_FILE 14
628 #define DICOM_FILE 15
629 #define MRI_ANALYZE4D_FILE 16
630 #define SIEMENS_DICOM_FILE 17
631 #define BRUKER_FILE 18
632 #define XIMG_FILE 19
633 #define NIFTI1_FILE 20 // NIfTI-1 .img + .hdr
634 #define IMAGE_FILE 21
635 #define MRI_GCA_FILE 22
636 #define BHDR 23 // for bshort or bfloat
637 #define NII_FILE 24 // NIfTI-1 .nii (single file)
638 #define MRI_CURV_FILE 25 // surface curv format
639
640 int MRImatch(MRI *mri1, MRI *mri2) ;
641 int MRInonzeroValRange(MRI *mri, float *pmin, float *pmax) ;
642 int MRIvalRange(MRI *mri, float *pmin, float *pmax) ;
643 int MRIvalRangeFrame(MRI *mri, float *pmin, float *pmax, int frame) ;
644 MRI *MRIvalScale(MRI *mri_src, MRI *mri_dst, float fmin, float fmax) ;
645 HISTOGRAM *MRIhistogram(MRI *mri, int nbins) ;
646 HISTOGRAM *MRIhistogramLabel(MRI *mri, MRI *mri_labeled,
647 int label, int nbins);
648 HISTOGRAM *MRIhistogramLabelRegion(MRI *mri,
649 MRI *mri_labeled,
650 MRI_REGION *region,
651 int label, int nbins);
652 MRI *MRIhistoEqualize(MRI *mri_src, MRI *mri_template, MRI *mri_dst,
653 int low, int high) ;
654 MRI *MRIapplyHistogram(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo) ;
655 MRI *MRIcrunch(MRI *mri_src, MRI *mri_dst) ;
656 HISTOGRAM *MRIgetEqualizeHisto(MRI *mri, HISTOGRAM *histo_eq, int low,
657 int high, int norm) ;
658
659 /* these are adaptive (i.e. only operate on a subregion of the whole image */
660 MRI_REGION *MRIclipRegion(MRI *mri, MRI_REGION *reg_src, MRI_REGION *reg_clip);
661 int MRIvalRangeRegion(MRI *mri, float *pmin, float *pmax,
662 MRI_REGION *region) ;
663 HISTOGRAM *MRIhistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo,
664 MRI_REGION *region) ;
665 HISTOGRAM *MRIhistogramLabelStruct(MRI *mri, int nbins, HISTOGRAM *histo,
666 LABEL *label) ;
667 MRI *MRIhistoEqualizeRegion(MRI *mri_src, MRI *mri_dst, int low,
668 MRI_REGION *region) ;
669 MRI *MRIapplyHistogramToRegion(MRI *mri_src, MRI *mri_dst,
670 HISTOGRAM *histo, MRI_REGION *region) ;
671 HISTOGRAM *MRIgetEqualizeHistoRegion(MRI *mri, HISTOGRAM *histo_eq, int low,
672 MRI_REGION *region, int norm) ;
673 int MRIfileType(char *fname) ;
674 int MRIunpackFileName(char *inFname, int *pframe, int *ptype,
675 char *outFname) ;
676 Volume MRItoVolume(MRI *mri) ;
677 MRI *MRIfromVolume(Volume volume, int start_frame, int end_frame) ;
678 int MRIisValid(MRI *mri) ;
679 MRI *MRIflipByteOrder(MRI *mri_src, MRI *mri_dst) ;
680
681 MRI *MRIregionGrow(MRI *mri_src, MRI *mri_distance,
682 float x0, float y0, float z0, int niter) ;
683 MRI *MRIextractInterior(MRI *mri_src, MRI *mri_distance, MRI *mri_dst);
684 MRI *MRIbuildDistanceMap(MRI *mri_src, MRI *mri_distance,
685 float x0, float y0, float z0, float r) ;
686 MRI *MRIupdateDistanceMap(MRI *mri_distance) ;
687 int MRIvalueFill(MRI *mri, float value);
688 MRI *MRIfill(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y,
689 int seed_z, int threshold, int fill_val, int max_count) ;
690 MRI *MRIfillFG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y,
691 int seed_z, int threshold, int fill_val, int *npix) ;
692 MRI *MRIfillBG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y,
693 int seed_z, int threshold, int fill_val, int *npix) ;
694
695 int MRIneighbors3x3(MRI *mri, int x, int y, int z, int val) ;
696 int MRIneighbors(MRI *mri, int x, int y, int z, int val) ;
697 int MRIneighborsOn(MRI *mri, int x0, int y0, int z0, int min_val) ;
698 int MRIneighborsOff(MRI *mri, int x0, int y0, int z0, int min_val) ;
699 int MRIneighborsOn3x3(MRI *mri, int x0, int y0, int z0, int min_val) ;
700 int MRIneighborsOff3x3(MRI *mri, int x0, int y0, int z0, int min_val) ;
701 int MRIlabelsInNbhd(MRI *mri, int x, int y, int z, int whalf, int label) ;
702
703 int MRIvol2Vol(MRI *src, MRI *targ, MATRIX *Vt2s,
704 int InterpCode, float param);
705
706 MRI *MRIresampleFill(MRI *src, MRI *template_vol,
707 int resample_type, float fill_val) ;
708 MRI *MRIreplaceValues(MRI *mri_src, MRI *mri_dst,
709 float in_val, float out_val) ;
710 MRI *MRIreplaceValuesUchar(MRI *mri_src, MRI *mri_dst,
711 BUFTYPE in_val, BUFTYPE out_val) ;
712 MRI *MRImask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask,
713 float out_val) ;
714 MRI *MRImaskInvert(MRI *mask, MRI *outmask);
715 int MRInMask(MRI *mask);
716
717 MRI *MRImeanMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst,
718 int mask, int wsize) ;
719 MRI *MRIthresholdMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst,
720 float mask_threshold, float out_val) ;
721
722 /* constants used in mri_dir of MRIoffsetDirection and for MRIminmax filter */
723 #define OFFSET_NEGATIVE_GRADIENT_DIRECTION 0
724 #define OFFSET_GRADIENT_DIRECTION 1
725 #define OFFSET_ZERO 2
726
727 /* anything below this is not white matter */
728 #define WM_MIN_VAL 5
729 #define MIN_WM_VAL WM_MIN_VAL
730 #define WM_EDITED_ON_VAL 255
731 #define WM_EDITED_OFF_VAL 1
732
733 MRI *MRIreduceMeanAndStdByte(MRI *mri_src, MRI *mri_dst) ;
734 MRI *MRIstdsToVariances(MRI *mri_std, MRI *mri_var, int source_frame) ;
735 MRI *MRIvariancesToStds(MRI *mri_var, MRI *mri_std, int dst_frame) ;
736 MRI *MRIconcatenateFrames(MRI *mri_frame1, MRI *mri_frame2, MRI *mri_dst);
737 MRI *MRIcopyFrame(MRI *mri_src, MRI *mri_dst, int src_frame, int dst_frame) ;
738 double MRImeanFrame(MRI *mri, int frame) ;
739
740 int MRIcountPlanarAboveThreshold(MRI *mri_src, int vertex, int x, int y,
741 int z, int wsize, int lo_lim, int hi_lim);
742 int MRIcountCpolvAtVoxel(MRI *mri_src, int x, int y, int z, int wsize,
743 int *pnum, int label_to_check) ;
744
745 MRI *MRIhistoSegment(MRI *mri_src, MRI *mri_labeled, int wm_low, int wm_hi,
746 int gray_hi, int wsize, float sigma) ;
747 MRI *MRIhistoSegmentVoxel(MRI *mri_src, MRI *mri_labeled, int wm_low,
748 int wm_hi, int gray_hi, int wsize, int x, int y,
749 int z, HISTOGRAM *histo, HISTOGRAM *hsmooth,
750 float sigma) ;
751 MRI *MRIcpolvSmooth(MRI *mri_orig,MRI *mri_src, MRI *mri_dst, int wsize,
752 int low_val, int hi_val, int niter) ;
753 MRI *MRIextractVertexCoords(MRI *mri_src, int *px, int *py, int *pz,
754 int vertex, int x, int y,int z, int wsize) ;
755
756 MRI *MRIextractVertexPlane(MRI *mri_src, MRI *mri_dst, int vertex, int x,
757 int y, int z, int wsize) ;
758 int MRIwhiteInPlane(MRI *mri_src, int x, int y, int z, int vertex, int wsize);
759 int MRIneighborhoodPlanarDirection(MRI *mri_src, int xv, int yv, int zv,
760 int nsize, int wsize) ;
761 int MRIneighborhoodCpolv(MRI *mri_src, int xv, int yv, int zv,int nsize,
762 int wsize, int *pnum_white) ;
763 int MRIneighborsInWindow(MRI *mri, int x, int y, int z, int wsize, int val) ;
764 int MRIneighborhoodBlackCpolv(MRI *mri_src, int xv, int yv, int zv,
765 int nsize, int wsize, int *pnum_black) ;
766
767 MRI *MRIorderSegment(MRI *mri_src, MRI *mri_labeled, float thresh, int wsize);
768 MRI *MRIthresholdLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst,
769 int wm_low) ;
770 MRI *MRIintensitySegmentation(MRI *mri_src, MRI *mri_labeled,
771 float wm_low, float wm_hi, float gray_hi) ;
772 MRI *MRImeanLabel(MRI *mri_src, MRI *mri_label, MRI*mri_dst, int wsize) ;
773 int MRIvoxelsInLabel(MRI *mri, int label) ;
774 int MRItotalVoxelsOn(MRI *mri, int thresh) ;
775 int MRIcopyLabel(MRI *mri_src, MRI *mri_dst, int val) ;
776 int MRIcopyLabeledVoxels(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst,
777 int label) ;
778 MRI *MRIcpolvVote(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wsize,
779 int niter, int use_all) ;
780 MRI *MRIcpolvThreshold(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst,
781 int wm_low, int gray_hi,int wsize) ;
782 MRI *MRImaskLabels(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) ;
783
784
785 MRI *MRIwmfilterMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize,
786 float pct, int onoff) ;
787 int MRIcountCpolvAtVoxel(MRI *mri_src, int x, int y, int z, int wsize,
788 int *pnum, int label_to_check) ;
789 int MRIcountCpolvOnAtVoxel(MRI *mri_src, int x, int y, int z, int wsize,
790 int *pnum) ;
791 MRI *MRIcentralPlaneOfLeastVarianceNormalMarked(MRI *mri_src, MRI *mri_mask,
792 MRI *mri_dst, int wsize) ;
793 int MRIcountCpolvOffAtVoxel(MRI *mri_src,int x, int y, int z, int wsize,
794 int *pnum) ;
795 int MRIcentralPlaneOfLeastVarianceNormalVoxel(MRI *mri_src, int wsize,
796 int x, int y, int z) ;
797 int MRIvertexToVector(int vertex, float *pdx, float *pdy, float *pdz) ;
798 int MRIcpolvMedianCurveVoxel(MRI *mri, MRI *mri_labeled, int x0, int y0,
799 int z0, int wsize, float len, float gray_hi,
800 float wm_low) ;
801 float MRIcpolvMedianAtVoxel(MRI *mri_src, int vertex,
802 float x, float y, float z, int wsize);
803 MRI *MRIcpolvMedianCurveSegment(MRI *mri,MRI *mri_labeled, MRI *mri_dst,
804 int wsize,float len, float gray_hi,
805 float wm_low);
806
807 MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) ;
808 int MRIborderClassifyVoxel(MRI *mri_src, MRI *mri_labeled, int wsize, int x,
809 int y, int z, float *ppw, float *ppg) ;
810 int MRIreclassifyBorder(MRI *mri_src, MRI *mri_labeled, MRI *mri_border,
811 MRI *mri_dst, int wsize) ;
812
813 int MRIclassifyAmbiguous(MRI *mri_src, MRI *mri_labeled, MRI *mri_border,
814 MRI *mri_dst, int wsize) ;
815
816 MRI *MRIremoveBrightStuff(MRI *mri_src, MRI *mri_dst, int threshold) ;
817 int MRIreclassify(MRI *mri_src, MRI *mri_labeled,
818 MRI *mri_dst, float wm_low, float gray_hi, int wsize) ;
819
820
821 MRI *MRImaskThreshold(MRI *mri_src, MRI *mri_mask, MRI *mri_dst,
822 float threshold, int out_label) ;
823 int MRIgrowLabel(MRI *mri, MRI *mri_bg, int in_label, int out_label) ;
824 int MRIturnOnFG(MRI *mri, MRI *mri_fg, MRI *mri_bg) ;
825 int MRIturnOffBG(MRI *mri, MRI *mri_bg) ;
826 /* mriprob.c */
827 MRI *MRIcomputeConditionalProbabilities(MRI *mri_T1, MRI *mri_mean,
828 MRI *mri_std, MRI *mri_dst) ;
829 MRI *MRIapplyBayesLaw(MRI *mri_priors, MRI *mri_p1, MRI *mri_p2,MRI *mri_dst);
830 MRI *MRIprobabilityThresholdNeighborhoodOff(MRI *mri_src, MRI *mri_prob,
831 MRI *mri_dst, float threshold,
832 int nsize) ;
833 MRI *MRIprobabilityThresholdNeighborhoodOn(MRI *mri_src, MRI *mri_prob,
834 MRI *mri_dst, float threshold,
835 int nsize, int out_label) ;
836 MRI *MRIprobabilityThreshold(MRI *mri_src, MRI *mri_prob, MRI *mri_dst,
837 float threshold, int out_label) ;
838 MRI *MRIdilateLabel(MRI *mri_src, MRI *mri_dst, int label, int niter) ;
839 MRI *MRIdilateLabelUchar(MRI *mri_src, MRI *mri_dst, int label, int niter) ;
840 MRI *MRIdilateThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label,
841 int niter, int thresh) ;
842 MRI *MRIdilateInvThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst,
843 int label,
844 int niter, int thresh) ;
845 MRI *MRIsoapBubbleLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst,
846 int label,
847 int niter);
848 MRI *MRIsetLabelValues(MRI *mri_src, MRI *mri_label, MRI *mri_dst,
849 int label, float val);
850 int MRIwriteImageViews(MRI *mri, char *base_name, int target_size) ;
851 int MRIsetValues(MRI *mri, float val) ;
852 MRI *MRIwindow(MRI *mri_src, MRI *mri_dst, int which, float x0, float y0,
853 float z0, float parm) ;
854 int MRIcomputeClassStatistics(MRI *mri_T1, MRI *mri_labeled,
855 float gray_low, float gray_hi,
856 float *pmean_wm, float *psigma_wm,
857 float *pmean_gm, float *psigma_gm) ;
858
859 #define WINDOW_GAUSSIAN 0
860 #define WINDOW_HAMMING 1
861 #define WINDOW_HANNING 2
862
863 #define MRI_NOT_WHITE 1
864 #define MRI_AMBIGUOUS 128
865 #define MRI_WHITE 255
866
867 #define MRI_LEFT_HEMISPHERE 255
868 #define MRI_RIGHT_HEMISPHERE 127
869 #define MRI_RIGHT_HEMISPHERE2 80
870
871
872 /* STATS volumes have 2 images each */
873 #define TRI_HI_PRIORS 0
874 #define TRI_HI_STATS 1
875 #define TRI_LOW_PRIORS 3
876 #define TRI_LOW_STATS 4
877 #define TRI_OFF_STATS 6
878
879
880 #define REMOVE_1D 2
881 #define REMOVE_WRONG_DIR 3
882
883 #define BASAL_GANGLIA_FILL 50
884 #define MAX_WM_VAL (THICKEN_FILL-1)
885 #define WM_MAX_VAL MAX_WM_VAL
886 #define THICKEN_FILL 200
887 #define NBHD_FILL 210
888 #define VENTRICLE_FILL 220
889 #define DIAGONAL_FILL 230
890 #define DEGENERATE_FILL 240
891 #define OFFSET_FILTER_FILL 245
892 #define AUTO_FILL 250
893 #define PRETESS_FILL 215
894
895 MRI *MRIchangeType(MRI *src, int dest_type, float f_low,
896 float f_high, int no_scale_option_flag);
897 MRI *MRISeqchangeType(MRI *vol, int dest_type, float f_low,
898 float f_high, int no_scale_option_flag);
899
900 MRI *MRIresample(MRI *src, MRI *template_vol, int resample_type);
901 MATRIX *MRIgetResampleMatrix(MRI *src, MRI *template_vol);
902 int MRIlimits(MRI *mri, float *min, float *max);
903 int MRIprintStats(MRI *mri, FILE *stream);
904 int MRIstats(MRI *mri, float *min, float *max, int *n_voxels,
905 float *mean, float *std);
906
907 float MRIvolumeDeterminant(MRI *mri);
908
909 int mriio_command_line(int argc, char *argv[]);
910 int mriio_set_subject_name(char *name);
911 int MRIgetVolumeName(char *string, char *name_only);
912 MRI *MRIread(char *fname);
913 MRI *MRIreadEx(char *fname, int nthframe);
914 MRI *MRIreadType(char *fname, int type);
915 MRI *MRIreadInfo(char *fname);
916 MRI *MRIreadHeader(char *fname, int type);
917 int GetSPMStartFrame(void);
918 int MRIwrite(MRI *mri, char *fname);
919 int MRIwriteFrame(MRI *mri, char *fname, int frame) ;
920 int MRIwriteType(MRI *mri, char *fname, int type);
921 int MRIwriteAnyFormat(MRI *mri, char *fileid, char *fmt,
922 int mriframe, MRIS *surf);
923 MRI *MRIreadRaw(FILE *fp, int width, int height, int depth, int type);
924 MRI *MRIreorder(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim);
925 MRI *MRIsmoothParcellation(MRI *mri, int smooth_parcellation_count);
926 MRI *MRIreadGeRoi(char *fname, int n_slices);
927
928 int decompose_b_fname(char *fname_passed, char *directory, char *stem);
929
930 #define READ_OTL_READ_VOLUME_FLAG 0x01
931 #define READ_OTL_FILL_FLAG 0x02
932 #define READ_OTL_TRANSLATE_LABELS_FLAG 0x04
933 #define READ_OTL_ZERO_OUTLINES_FLAG 0x08
934 MRI *MRIreadOtl(char *fname, int width, int height, int slices,
935 char *color_file_name, int flags);
936
937 MATRIX *extract_i_to_r(MRI *mri);
938 int apply_i_to_r(MRI *mri, MATRIX *m);
939
940 int stuff_four_by_four(MATRIX *m,
941 float m11, float m12, float m13, float m14,
942 float m21, float m22, float m23, float m24,
943 float m31, float m32, float m33, float m34,
944 float m41, float m42, float m43, float m44);
945
946 MATRIX *extract_r_to_i(MRI *mri) ;
947 #define MRIgetVoxelToRasXform extract_i_to_r
948 #define MRIgetRasToVoxelXform extract_r_to_i
949 int MRIsetVoxelToRasXform(MRI *mri, MATRIX *m_vox2ras) ;
950 MATRIX *MRIvoxelXformToRasXform(MRI *mri_src, MRI *mri_dst,
951 MATRIX *m_voxel_xform, MATRIX *m_ras_xform);
952 MATRIX *MRIrasXformToVoxelXform(MRI *mri_src, MRI *mri_dst,
953 MATRIX *m_ras_xform, MATRIX *m_voxel_xform);
954
955
956 int MRIsincSampleVolume(MRI *mri, Real x, Real y, Real z, int hw, Real *pval);
957 int MRIcubicSampleVolume(MRI *mri, Real x, Real y, Real z, Real *pval); /*E*/
958 MRI *MRIsincTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int hw);
959 int MRIlabelOverlap(MRI *mri1, MRI *mri2, int label) ;
960 int MRIeraseBorderPlanes(MRI *mri) ;
961
962 MRI *MRIlog10(MRI *inmri, MRI *outmri, int negflag);
963 MRI *MRIrandn(int ncols, int nrows, int nslices, int nframes,
964 float avg, float stddev, MRI *mri);
965 MRI *MRIrande(int ncols, int nrows, int nslices, int nframes,
966 float avg, int order, MRI *mri);
967 MRI *MRIdrand48(int ncols, int nrows, int nslices, int nframes,
968 float min, float max, MRI *mri);
969 MRI *MRIsampleCDF(int ncols, int nrows, int nslices, int nframes,
970 double *xCDF, double *CDF, int nCDF, MRI *mri);
971 MRI *MRIconst(int ncols, int nrows, int nslices, int nframes,
972 float val, MRI *mri);
973 int MRInormalizeSequence(MRI *mri, float target) ;
974
975 int setDirectionCosine(MRI *mri, int orientation);
976 int getSliceDirection(MRI *mri);
977 int mriOKforSurface(MRI *mri); // check whether the volume is conformed or not
978 int mriConformed(MRI *mri) ;
979 void setMRIforSurface(MRI *mri); // set c_(r,a,s) = 0 for a conformed volume
980 MRI *MRIremoveNaNs(MRI *mri_src, MRI *mri_dst) ;
981 MRI *MRImakePositive(MRI *mri_src, MRI *mri_dst);
982 MRI *MRIeraseNegative(MRI *mri_src, MRI *mri_dst) ;
983
984 MRI *MRImarkLabelBorderVoxels(MRI *mri_src, MRI *mri_dst,
985 int label, int mark, int six_connected) ;
986 int MRIcomputeLabelNbhd(MRI *mri_labels, MRI *mri_vals,
987 int x, int y, int z,
988 int *label_counts, float *label_means,
989 int whalf, int max_labels) ;
990 float MRIvoxelsInLabelWithPartialVolumeEffects(MRI *mri, MRI *mri_vals,
991 int label) ;
992 MRI *MRImakeDensityMap(MRI *mri, MRI *mri_vals, int label, MRI *mri_dst) ;
993 int MRIcropBoundingBox(MRI *mri, MRI_REGION *box) ;
994 MRI *MRIapplyBiasCorrection(MRI *mri_in, MRI *mri_bias, MRI *mri_out) ;
995 MRI *MRIapplyBiasCorrectionSameGeometry(MRI *mri_in, MRI *mri_bias,
996 MRI *mri_out, float target_val) ;
997 MATRIX *MRIgetVoxelToVoxelXform(MRI *mri_src, MRI *mri_dst) ;
998
999 /* extract the RASToVoxeMatrix from an MRI */
1000 MATRIX *GetSurfaceRASToVoxelMatrix(MRI *mri);
1001
1002 /* Zero-padding for 3d analyze (ie, spm) format */
1003 #ifdef _MRIIO_SRC
1004 int N_Zero_Pad_Input = -1;
1005 int N_Zero_Pad_Output = -1;
1006 #else
1007 extern int N_Zero_Pad_Input;
1008 extern int N_Zero_Pad_Output;
1009 #endif
1010
1011 float MRIfovCol(MRI *mri);
1012 int MRIdircosToOrientationString(MRI *mri, char *ostr);
1013 int MRIorientationStringToDircos(MRI *mri, char *ostr);
1014 char *MRIcheckOrientationString(char *ostr);
1015 char *MRIsliceDirectionName(MRI *mri);
1016 MRI *MRIreverseSliceOrder(MRI *invol, MRI *outvol);
1017
1018 /* different modes for distance transform - signed
1019 (<0 in interior) unsigned from border, or
1020 just outside (interior is 0) */
1021 #define DTRANS_MODE_SIGNED 1
1022 #define DTRANS_MODE_UNSIGNED 2
1023 #define DTRANS_MODE_OUTSIDE 3
1024 MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist,
1025 int label, float max_dist, int mode);
1026 int MRIaddCommandLine(MRI *mri, char *cmdline) ;
1027 int MRIcopyVolGeomToMRI(MRI *mri, VOL_GEOM *vg) ;
1028 MRI *MRInonMaxSuppress(MRI *mri_src, MRI *mri_sup,
1029 float thresh, int thresh_dir) ;
1030 MRI *MRIextractRegionAndPad(MRI *mri_src, MRI *mri_dst,
1031 MRI_REGION *region, int pad) ;
1032 MRI *MRIsetValuesOutsideRegion(MRI *mri_src,
1033 MRI_REGION *region,
1034 MRI *mri_dst,
1035 float val) ;
1036 int MRIcountNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) ;
1037
1038 #endif
1039
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.You are not allowed to attach a file to this page.
