/
mri.h
1946 lines (1734 loc) · 85.2 KB
/
mri.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @brief prototypes and structures for working with MRI volumes.
*
* prototypes and structures for working with MRI volumes.
*/
/*
* Original Author: Bruce Fischl
*
* Copyright © 2021 The General Hospital Corporation (Boston, MA) "MGH"
*
* Terms and conditions for use, reproduction, distribution and contribution
* are found in the 'FreeSurfer Software License Agreement' contained
* in the file 'LICENSE' found in the FreeSurfer distribution, and here:
*
* https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
*
* Reporting: freesurfer@nmr.mgh.harvard.edu
*
*/
#ifndef MRI_H
#define MRI_H
#include <vector>
#include <array>
#include <string>
#include "faster_variants.h"
#include "minc.h"
#include "const.h"
#include "matrix.h"
#include "dmatrix.h"
#include "machine.h"
#include "colortab.h"
#include "affine.h"
#include "fnvhash.h"
#include "itkImage.h"
#include "warpfield.h"
#include "fio.h"
#define BUFTYPE unsigned char
#define SAMPLE_NEAREST 0
#define SAMPLE_TRILINEAR 1
#define SAMPLE_SINC 2
#define SAMPLE_CUBIC 3 /*E*/
#define SAMPLE_WEIGHTED 4
#define SAMPLE_CUBIC_BSPLINE 5
#define SAMPLE_VOTE 6 // for downsampling aseg volumes
#define MRI_UCHAR 0
#define MRI_INT 1
#define MRI_LONG 2
#define MRI_FLOAT 3
#define MRI_SHORT 4
#define MRI_BITMAP 5
#define MRI_TENSOR 6
#define MRI_FLOAT_COMPLEX 7
#define MRI_DOUBLE_COMPLEX 8
#define MRI_RGB 9
#define MRI_USHRT 10
#define NEAREST_NEIGHBOR_FACE 1
#define NEAREST_NEIGHBOR_EDGE 2
#define NEAREST_NEIGHBOR_CORNER 3
#define MAX_CMDS 1000
#define SEQUENCE_MPRAGE 1
#define SEQUENCE_EPI 2
#define FRAME_TYPE_ORIGINAL 0
#define FRAME_TYPE_DIFFUSION_AUGMENTED 1
#define MRInvox(mri) ((mri)->width * (mri)->height * (mri)->depth * (mri)->nframes)
#define BVEC_SPACE_UNKNOWN 0
#define BVEC_SPACE_SCANNER 1
#define BVEC_SPACE_VOXEL 2
#define MB_RADIAL 0
#define MB_TANGENTIAL 1
#define FS_COORDS_UNKNOWN 0
#define FS_COORDS_TKREG_RAS 1 // same as surfaceRAS
#define FS_COORDS_SCANNER_RAS 2 // same as surface "RealRAS"
#define FS_COORDS_VOXEL 3
// standard itk image type
typedef itk::Image<float, 3> ITKImageType;
// struct MRI_FRAME is used in trc/dmri_mergepaths.cxx and freeview/LayerVolumeTrack.cpp.
// The only fields used are label, name, and thresh.
// m_ras2vox is initialized to identity matrix, but not used.
// TAG_MRI_FRAME in .mgz/.mgh outputs the whole struct. Keep this struct for the program and data backward compatible.
// TAG_MRI_FRAME in Freesurfer nifti header extension only outputs fields label, name, and thresh.
typedef struct
{
int type ; // code for what is stored in this frame
float TE ; // echo time
float TR ; // recovery time
float flip ; // flip angle
float TI ; // time-to-inversion
float TD ; // delay time
int sequence_type ; // see SEQUENCE* constants
float echo_spacing ;
float echo_train_len ; // length of the echo train
float read_dir[3] ; // read-out direction in RAS coords
float pe_dir[3] ; // phase-encode direction in RAS coords
float slice_dir[3] ; // slice direction in RAS coords
int label ; // index into CLUT
char name[STRLEN] ; // human-readable description of frame contents
int dof ; // for stat maps (e.g. # of subjects)
MATRIX *m_ras2vox ;
float thresh ;
int units ; // e.g. UNITS_PPM, UNITS_RAD_PER_SEC, ...
// for Herr Dr. Prof. Dr. Dr. Witzel
// directions: maybe best in both reference frames
// or just 3 coordinates and a switch which frame it is ?
double DX ;
double DY ;
double DZ ;
double DR ;
double DP ;
double DS ;
// B-value
double bvalue ;
// Mixing time
double TM ;
// What kind of diffusion scan is this (can be an enum)
// stejskal-tanner,trse,steam etc....
long diffusion_type ;
// Gradient values
long D1_ramp ;
long D1_flat ;
double D1_amp ;
long D2_ramp ;
long D2_flat ;
double D2_amp ;
long D3_ramp ;
long D3_flat ;
double D3_amp ;
long D4_ramp ;
long D4_flat ;
double D4_amp ;
} MRI_FRAME ;
typedef struct
{
int x ;
int y ;
int z ;
int dx ;
int dy ;
int dz ;
}
MRI_REGION ;
// forward declarations
struct VOL_GEOM;
class FStagsIO;
MATRIX *MRIxfmCRS2XYZ( const VOL_GEOM *mri, int base ); /* Native Vox2RAS Matrix (scanner and xfm too) */
MATRIX *MRIxfmCRS2XYZtkreg( const VOL_GEOM *mri ); // TkReg Vox2RAS Matrix
MATRIX *VGras2tkreg(VOL_GEOM *vg, MATRIX *ras2tkreg);
MATRIX *VGtkreg2RAS(VOL_GEOM *vg, MATRIX *tkreg2ras);
// transform.cpp::initVolGeom(VOL_GEOM *) : valid = 0; width = height = depth = 256
// VOL_GEOM doesn’t initialize valid, width, height, depth
struct VOL_GEOM
{
// NOTE: VOL_GEOM is subclassed by MRI, so take that into account when changing
int valid; /* whether this is a valid info or not (1 valid, 0 not valid) */
int width ;
int height ;
int depth ;
float xsize = 1; // Added =1 because that is what MRI does
float ysize = 1;
float zsize = 1;
int ras_good_flag = 0; // indicates whether the RAS coordinates are accurate
float x_r = -1, x_a = 0, x_s = 0;
float y_r = 0, y_a = 0, y_s = -1;
float z_r = 0, z_a = 1, z_s = 0;
float c_r = 0, c_a = 0, c_s = 0;
char fname[STRLEN] = {'\0'}; // volume filename
// i_to_r__, r_to_i__, register_mat were moved here from MRI in this commit:
// https://github.com/freesurfer/freesurfer/commit/d7b80d733e96380543093e1bb0c11f0123f97132
AffineMatrix *i_to_r__ = nullptr; // cached i->r transform
MATRIX *r_to_i__ = nullptr; // cached r->i transform
MATRIX *register_mat = nullptr;
// The functions below compute these matrices on-the-fly
// RAS = scanner RAS (sometimes known as "real" RAS in surface contexts)
// TkregRAS = RAS used by tkregister; surface coords are by default in this TkregRAS space
MATRIX *get_Vox2RAS(int base=0){ return(MRIxfmCRS2XYZ(this,base));}
MATRIX *get_RAS2Vox(int base=0){ return(MatrixInverse(get_Vox2RAS(base),NULL));}
MATRIX *get_Vox2TkregRAS(void){ return(MRIxfmCRS2XYZtkreg(this));}
MATRIX *get_TkregRAS2Vox(void){ return(MatrixInverse(get_Vox2TkregRAS(),NULL));}
MATRIX *get_RAS2TkregRAS(void){ return(VGras2tkreg(this, NULL));}
MATRIX *get_TkregRAS2RAS(void){ return(VGtkreg2RAS(this, NULL));}
VOL_GEOM() {}
// copy constructor
VOL_GEOM(const VOL_GEOM& vg)
{
valid = vg.valid;
width = vg.width;
height = vg.height;
depth = vg.depth;
xsize = vg.xsize;
ysize = vg.ysize;
zsize = vg.zsize;
ras_good_flag = vg.ras_good_flag;
x_r = vg.x_r;
x_a = vg.x_a;
x_s = vg.x_s;
y_r = vg.y_r;
y_a = vg.y_a;
y_s = vg.y_s;
z_r = vg.z_r;
z_a = vg.z_a;
z_s = vg.z_s;
c_r = vg.c_r;
c_a = vg.c_a;
c_s = vg.c_s;
strcpy(fname, vg.fname);
#if 0
// ??? valid and ras_good_flag mean the same thing ???
valid = (ras_good_flag) ? ras_good_flag : valid;
ras_good_flag = (valid) ? valid : ras_good_flag;
#endif
}
// copy assignment
VOL_GEOM& operator= (const VOL_GEOM& other)
{
valid = other.valid;
width = other.width;
height = other.height;
depth = other.depth;
xsize = other.xsize;
ysize = other.ysize;
zsize = other.zsize;
ras_good_flag = other.ras_good_flag;
x_r = other.x_r;
x_a = other.x_a;
x_s = other.x_s;
y_r = other.y_r;
y_a = other.y_a;
y_s = other.y_s;
z_r = other.z_r;
z_a = other.z_a;
z_s = other.z_s;
c_r = other.c_r;
c_a = other.c_a;
c_s = other.c_s;
strcpy(fname, other.fname);
#if 0
// ??? valid and ras_good_flag mean the same thing ???
valid = (ras_good_flag) ? ras_good_flag : valid;
ras_good_flag = (valid) ? valid : ras_good_flag;
#endif
return *this;
}
void vgprint(bool nocheck=false)
{
if (valid == 1 || nocheck) {
fprintf(stdout, "volume geometry:\n");
if (nocheck)
fprintf(stdout, "valid : %d\n", valid);
fprintf(stdout, "extent : (%d, %d, %d)\n", width, height, depth);
fprintf(stdout, "voxel : (%7.4f, %7.4f, %7.4f)\n", xsize, ysize, zsize);
fprintf(stdout, "x_(ras) : (%7.4f, %7.4f, %7.4f)\n", x_r, x_a, x_s);
fprintf(stdout, "y_(ras) : (%7.4f, %7.4f, %7.4f)\n", y_r, y_a, y_s);
fprintf(stdout, "z_(ras) : (%7.4f, %7.4f, %7.4f)\n", z_r, z_a, z_s);
fprintf(stdout, "c_(ras) : (%7.4f, %7.4f, %7.4f)\n", c_r, c_a, c_s);
fprintf(stdout, "file : %s\n", fname);
}
else
fprintf(stdout, "volume geometry: info is either not contained or not valid.\n");
fflush(stdout);
}
// return 1 if two VOL_GEOMs equal;
// otherwise, return 0
int operator== (const VOL_GEOM& vg)
{
extern double vg_isEqual_Threshold;
int rt = isNotEqualThresh(this, &vg, vg_isEqual_Threshold);
return (rt == 0) ? 1 : 0;
}
// if two VOL_GEOMs equal, return 0;
// otherwise, return number > 0
static int isNotEqualThresh(const VOL_GEOM *vg1, const VOL_GEOM *vg2, const double thresh)
{
if (vg1->valid != vg2->valid) return (1);
if (vg1->width != vg2->width) return (2);
if (vg1->height != vg2->height) return (3);
if (vg1->depth != vg2->depth) return (4);
if (!FZEROTHR(vg1->xsize - vg2->xsize, thresh)) return (5);
if (!FZEROTHR(vg1->ysize - vg2->ysize, thresh)) return (6);
if (!FZEROTHR(vg1->zsize - vg2->zsize, thresh)) return (7);
if (!FZEROTHR(vg1->x_r - vg2->x_r, thresh)) return (8);
if (!FZEROTHR(vg1->x_a - vg2->x_a, thresh)) return (9);
if (!FZEROTHR(vg1->x_s - vg2->x_s, thresh)) return (10);
if (!FZEROTHR(vg1->y_r - vg2->y_r, thresh)) return (11);
if (!FZEROTHR(vg1->y_a - vg2->y_a, thresh)) return (12);
if (!FZEROTHR(vg1->y_s - vg2->y_s, thresh)) return (13);
if (!FZEROTHR(vg1->z_r - vg2->z_r, thresh)) return (14);
if (!FZEROTHR(vg1->z_a - vg2->z_a, thresh)) return (15);
if (!FZEROTHR(vg1->z_s - vg2->z_s, thresh)) return (16);
if (!FZEROTHR(vg1->c_r - vg2->c_r, thresh)) return (17);
if (!FZEROTHR(vg1->c_a - vg2->c_a, thresh)) return (18);
if (!FZEROTHR(vg1->c_s - vg2->c_s, thresh)) return (19);
return (0);
};
// write VOL_GEOM to znzFile
void write(znzFile fp, bool niftiheaderext=false)
{
znzwriteInt(valid, fp);
znzwriteInt(width, fp);
znzwriteInt(height, fp);
znzwriteInt(depth, fp);
znzwriteFloat(xsize, fp);
znzwriteFloat(ysize, fp);
znzwriteFloat(zsize, fp);
znzwriteFloat(x_r, fp);
znzwriteFloat(x_a, fp);
znzwriteFloat(x_s, fp);
znzwriteFloat(y_r, fp);
znzwriteFloat(y_a, fp);
znzwriteFloat(y_s, fp);
znzwriteFloat(z_r, fp);
znzwriteFloat(z_a, fp);
znzwriteFloat(z_s, fp);
znzwriteFloat(c_r, fp);
znzwriteFloat(c_a, fp);
znzwriteFloat(c_s, fp);
int len_max = 512;
if (!niftiheaderext)
{
char buf[len_max];
memset(buf, 0, len_max * sizeof(char));
memcpy(buf, fname, len_max);
znzwrite(buf, sizeof(char), len_max, fp);
}
else
{
// variable length fname, if length = 0, no fname output follows
int len_fname = strlen(fname);
len_fname = (len_fname > len_max) ? len_max : len_fname;
znzwriteInt(len_fname, fp);
//printf("[DEBUG] VOL_GEOM::write() fname length= %-4d (%s)\n", len_fname, fname);
if (len_fname > 0)
znzwrite(fname, sizeof(char), len_fname, fp);
}
}
// read VOL_GEOM from znzFile
void read(znzFile fp, bool niftiheaderext=false)
{
valid = znzreadInt(fp);
width = znzreadInt(fp);
height = znzreadInt(fp);
depth = znzreadInt(fp);
xsize = znzreadFloat(fp);
ysize = znzreadFloat(fp);
zsize = znzreadFloat(fp);
x_r = znzreadFloat(fp);
x_a = znzreadFloat(fp);
x_s = znzreadFloat(fp);
y_r = znzreadFloat(fp);
y_a = znzreadFloat(fp);
y_s = znzreadFloat(fp);
z_r = znzreadFloat(fp);
z_a = znzreadFloat(fp);
z_s = znzreadFloat(fp);
c_r = znzreadFloat(fp);
c_a = znzreadFloat(fp);
c_s = znzreadFloat(fp);
int len_max = 512;
if (!niftiheaderext)
{
memset(fname, 0, len_max * sizeof(char));
znzread(fname, sizeof(char), len_max, fp);
}
else
{
// variable length fname, if length = 0, no fname output follows
// read the first len_max bytes, skip the rest
int len_fname = znzreadInt(fp);
int to_read = (len_fname > len_max) ? len_max : len_fname;
if (to_read > 0)
{
znzread(fname, sizeof(char), to_read, fp);
//printf("[DEBUG] VOL_GEOM::read() fname length= %-4d (%s)\n", to_read, fname);
// skip the remaining bytes
int remaining = len_fname - to_read;
if (remaining > 0)
{
char buf[remaining];
znzread(buf, sizeof(char), remaining, fp);
//printf("[DEBUG] VOL_GEOM::read() fname skipped bytes = %-4d\n", remaining);
}
}
}
}
};
typedef VOL_GEOM VG;
#define MGH_VERSION 1 // this is the mgz format version
// version number in .mgz will be constructed using these defines
// ex. ((MGZ_INTENT_WARPMAP & 0xff ) << 8) | MGH_VERSION
// ((MGZ_INTENT_WARPMAP_INV & 0xff ) << 8) | MGH_VERSION
#define MGZ_INTENT_UNKNOWN -1
#define MGZ_INTENT_MRI 0
#define MGZ_INTENT_LABEL 1
#define MGZ_INTENT_SHAPE 2
#define MGZ_INTENT_WARPMAP 3
#define MGZ_INTENT_WARPMAP_INV 4
class MRI : public VOL_GEOM
{
public:
class Shape
{
public:
Shape() {};
Shape(const std::vector<int>& shape);
Shape(const std::vector<ssize_t>& shape) : Shape(std::vector<int>(shape.begin(), shape.end())) {};
Shape(const std::initializer_list<int>& shape) : Shape(std::vector<int>(shape)) {}
ssize_t width, height, depth, nframes, size;
operator std::vector<ssize_t>() const { return {width, height, depth, nframes}; }
friend bool operator == (const Shape &l, const Shape &r) { return (std::vector<ssize_t>(l) == std::vector<ssize_t>(r)); }
friend bool operator != (const Shape &l, const Shape &r) { return !(l == r); }
};
MRI(const VOL_GEOM& vg, int dtype, int nframes=1, int HeaderOnly=1);
MRI(const Shape volshape, int dtype, bool alloc = true);
//MRI(const std::string& filename);
~MRI();
static const char* intentName(int code);
static int intentCode(const char *name);
void initIndices();
void initSlices();
void write(const std::string& filename);
FnvHash hash();
// ITK image conversions
ITKImageType::Pointer toITKImage(int frame = 0);
void loadITKImage(ITKImageType::Pointer image, int frame = 0);
// ---- image geometry ----
//int width; // number of columns // Now inherited from VOL_GEOM
//int height; // number of rows // Now inherited from VOL_GEOM
//int depth; // number of slices // Now inherited from VOL_GEOM
int nframes; // number of frames
Shape shape; // volume shape
int imnr0; // starting image number
int imnr1; // ending image number
float xstart; // starting x (in xsize units)
float ystart; // starting y (in ysize units)
float zstart; // starting z (in zsize units)
float xend; // ending x (in xsize units)
float yend; // ending y (in ysize units)
float zend; // ending z (in zsize units)
//float xsize = 1; // size of a voxel in the x direction // Now inherited from VOL_GEOM
//float ysize = 1; // size of a voxel in the y direction // Now inherited from VOL_GEOM
//float zsize = 1; // size of a voxel in the z direction // Now inherited from VOL_GEOM
float thick = 1;
int scale = 1;
float ps = 1;
float fov;
// ---- indices to handle boundary conditions ----
int *xi = nullptr;
int *yi = nullptr;
int *zi = nullptr;
// ---- RAS distances ---- // Now inherited from VOL_GEOM
//float x_r = -1, x_a = 0, x_s = 0;
//float y_r = 0, y_a = 0, y_s = -1;
//float z_r = 0, z_a = 1, z_s = 0;
//float c_r = 0, c_a = 0, c_s = 0;
//int ras_good_flag = 0; // indicates whether the RAS coordinates are accurate
// ---- transforms ----
char transform_fname[STRLEN];
General_transform transform;
Transform *linear_transform = nullptr;
Transform *inverse_linear_transform = nullptr;
int free_transform = 0;
MATRIX *AutoAlign = nullptr; // for Andre
// ---- volume metadata ----
double outside_val = 0;
double mean;
int brightness = 1;
int yinvert = 1; // for converting between MNC and coronal slices
int dof = 1;
MRI_FRAME *frames = nullptr;
COLOR_TABLE *ct = nullptr;
MRI_REGION roi;
// ---- scan parameters ----
float tr = 0; // time to recovery, nifti1 hdr.pixdim[4]
float te = 0; // time to echo
float ti = 0; // time to inversion
double flip_angle = 0; // flip angle in radians
float FieldStrength = 0; // field strength
char *pedir = nullptr; // phase enc direction: ROW, COL, etc
MATRIX *origRas2Vox = nullptr ; // to get to original voxel grid from ras
// can be set from mri_convert --store_orig_ras2vox (-so)
float location = 0; // NOT USED
// ---- DTI ----
int bvec_space = 0; // 0: unknown, 1: scanner, 2: voxel
MATRIX *bvals = nullptr;
MATRIX *bvecs = nullptr;
// ---- file metadata ----
//char fname[STRLEN]; // filename // Now inherited from VOL_GEOM
int version = MGH_VERSION;
int intent = MGZ_INTENT_MRI;
VOL_GEOM gcamorph_image_vg;
VOL_GEOM gcamorph_atlas_vg;
char fnamePostFixes[STRLEN]; // used in MRIwrite(), append to output file name
int len_fnamePostFixes;
char fname_format[STRLEN]; // file extension
char subject_name[STRLEN]; // fs subject name
char path_to_t1[STRLEN]; // NOT USED
char gdf_image_stem[STRLEN];
char *cmdlines[MAX_CMDS]; // command line provenance
int ncmds = 0; // number of commands run previously
// tag_data and tag_data_size don't seem to be used (2024-01-11)
//void *tag_data = nullptr; // saved tag data
//int tag_data_size = 0; // size of tag data
// ---- TAG_GCAMORPH_META ----
int warpFieldFormat = WarpfieldDTFMT::WARPFIELD_DTFMT_UNKNOWN;
int gcamorphSpacing = 1; // spacing in GCA_MORPH
double gcamorphExp_k = 0.0; // exp_k in GCA_MORPH
MATRIX *gcamorphAffine = nullptr; // m_affine in GCA_MORPH
int ***gcamorphLabel = nullptr; // label in GCA_MORPH_NODE
void initGCAMorphLabel();
// ---- image buffer ----
int type; // image data type
int ptype = 2; // NOT USED
size_t bytes_per_vox = 0; // bytes per voxel
size_t bytes_total = 0; // total bytes in buffer
size_t vox_per_row = 0; // number of voxels per volume row
size_t vox_per_slice = 0; // number of voxels per volume slice
size_t vox_per_vol = 0; // number of voxels per volume frame
size_t vox_total = 0; // total number of voxels in the volume
int ischunked; // indicates whether the buffer is chunked (contiguous)
bool owndata = true; // indicates ownership of the chunked buffer data
BUFTYPE ***slices = nullptr; // fallback non-contiguous storage for 3D-indexed image data
void *chunk = nullptr; // default contiguous storage for image data
};
typedef struct
{
int type; // MB_RADIAL or MB_TANGENTIAL
double offset,slope; //Offset is in mm; Slope is per centimeter (not mm)
int c0,r0; // center of motion in full volume space
int cR,rR; // col and row of first voxel of region in full volume space
double DeltaD; // sample spacing along radius
double cutoff; // number of stddevs to cut off kernel
int Interp; // SAMPLE_NEAREST or SAMPLE_TRILINEAR
MRI *d0; // Image of distance to voxel from center
MRI *theta; // Image of angle of voxel
MRI *fwhm; // Image of FWHM at voxel
MRI *dmin; // Image of start distance (cut off)
MRI *nd; // Image of number of samples
} MOTIONBLUR2D, MB2D;
MRI *MRImotionBlur2D(MRI *src, MB2D *mb, MRI *out);
int MB2Dfree(MB2D **pmb);
MB2D *MB2Dcopy(MB2D *src, int CopyMRI, MB2D *copy);
MRI *MB2Dgrid(MRI *mbtemplate, int skip, MRI *outvol);
MATRIX *MRIcopyFramesToMatrixRows(MRI *mri, MATRIX *m_dst, int start_frame, int nframes, int dst_row) ;
MATRIX *vg_i_to_r(const VOL_GEOM *vg);
MATRIX *vg_r_to_i(const VOL_GEOM *vg);
#define vg_getRasToVoxelXform vg_r_to_i
#define vg_getVoxelToRasXform vg_i_to_r
MATRIX *TkrVox2RASfromVolGeom(const VOL_GEOM *vg);
MATRIX *TkrRAS2VoxfromVolGeom(const VOL_GEOM *vg);
MATRIX *MRIxfmCRS2XYZfsl(VOL_GEOM *mri); // FSL/FLIRT Vox2RAS Matrix
int MRIsetVox2RASFromMatrix(VOL_GEOM *mri, MATRIX *m_vox2ras);
int MRIsetVox2RASFromMatrixUnitTest(MRI *mri);
MATRIX *MRItkRegMtxFromVox2Vox(VOL_GEOM *ref, VOL_GEOM *mov, MATRIX *vox2vox);//ras2ras from vox2vox
MATRIX *MRItkReg2Native(VOL_GEOM *ref, VOL_GEOM *mov, MATRIX *R); /* tkreg2native (scanner and xfm too) */
MATRIX *MRItkRegMtx(VOL_GEOM *ref, VOL_GEOM *mov, MATRIX *D); /* native2tkreg (scanner and xfm too) */
MATRIX *MRIvoxToVoxFromTkRegMtx(VOL_GEOM *mov, VOL_GEOM *targ, MATRIX *tkR);
MATRIX *MRIfsl2TkReg(VOL_GEOM *ref, VOL_GEOM *mov, MATRIX *FSLRegMat);
MATRIX *MRItkreg2FSL(VOL_GEOM *ref, VOL_GEOM *mov, MATRIX *tkRegMat);
MATRIX *MtxCRS1toCRS0(MATRIX *Q);
int MRIp0ToCRAS(VOL_GEOM *mri, double r0, double a0, double s0);
MATRIX *MRIfixTkReg(VOL_GEOM *mov, MATRIX *R);
MATRIX *MRImatrixOfDirectionCosines(VOL_GEOM *mri, MATRIX *Mdc);
MATRIX *MRImatrixOfVoxelSizes(VOL_GEOM *mri, MATRIX *D);
MATRIX *MRImatrixOfTranslations(VOL_GEOM *mri, MATRIX *P0);
int MRIhfs2Sphinx(VOL_GEOM *mri);
float MRIgetVoxDx(MRI *mri, int c, int r, int s, int f);
float MRIgetVoxDy(MRI *mri, int c, int r, int s, int f);
float MRIgetVoxDz(MRI *mri, int c, int r, int s, int f);
float MRIgetVoxVal( const MRI *mri, int c, int r, int s, int f);
float MRIgetVoxVal2( const MRI *mri, int c, int r, int s, int f);
int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval);
int MRIsetVoxVal2(MRI *mri, int c, int r, int s, int f, float voxval);
void MRIdbl2ptr(double v, void *pmric, int mritype);
double MRIptr2dbl(void *pmric, int mritype);
size_t MRIsizeof(int mritype);
const char * MRIprecisionString(int PrecisionCode);
int MRIprecisionCode(const char *PrecisionString);
MRI *MRImakeMosaic(MRI **mri, int nimages, int rectify) ;
int MRIareNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) ;
float MRIfindNearestNonzero(MRI *mri,
int wsize,
double x0, double y0, double z0,
float max_dist) ;
float MRIfindNearestNonzeroLocation(MRI *mri, int wsize,
double xr, double yr, double zr,
int *pxv, int *pyv, int *pzv) ;
/* single pixel filtering */
float MRIvoxelMedian(MRI *mri, int x0, int y0, int z0, int wsize) ;
float MRIvoxelMean( const MRI *mri, int x, int y, int z, int wsize, int frame) ;
float MRIvoxelMin(MRI *mri, int x0, int y0, int z0, int wsize) ;
float MRIvoxelMax(MRI *mri, int x0, int y0, int z0, int wsize) ;
float MRIvoxelStd(MRI *mri, int x, int y, int z, float mean, int wsize) ;
float MRIvoxelZscore(MRI *mri, int x, int y, int z, int wsize) ;
float MRIvoxelDx(MRI *mri, int x, int y, int z) ;
float MRIvoxelDy(MRI *mri, int x, int y, int z) ;
float MRIvoxelDz(MRI *mri, int x, int y, int z) ;
float MRIvoxelGradient(MRI *mri, int x, int y, int z, float *pdx, float *pdy,
float *pdz) ;
float MRIvoxelDirection(MRI *mri, int x, int y, int z, int wsize) ;
MRI *MRI2ndDirectionalDerivative(MRI *mri_src, MRI *mri_deriv, float nx, float ny, float nz) ;
float MRIvoxelGradientDir2ndDerivative(MRI *mri, int x0, int y0, int z0,
int wsize) ;
MRI * MRIgradientDir2ndDerivative(MRI *mri_src, MRI *mri_dst, int wsize) ;
double MRImeanFrameThresh(MRI *mri, int frame, float thresh);
/* use these constants for MRIreorder */
#define XDIM 1
#define YDIM 2
#define ZDIM 3
/* ch ov */
/*
MRI *MRIreorder(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim);
*/
/* I/O functions */
/* ch ov */
/*
int MRIwrite(MRI *mri, char *fpref) ;
*/
int MRIwriteInfo(MRI *mri,const char *fpref) ;
/* ch ov */
/*
MRI *MRIread(char *fpref) ;
MRI *MRIreadInfo(char *fpref) ;
*/
/* memory allocation routines */
int MRIfree(MRI **pmri) ;
MRI *MRIalloc(int width, int height, int depth, int type) ;
MRI *MRIallocSequence(int width, int height,int depth,int type,int nframes);
MRI *MRIallocHeader(int width, int height, int depth, int type, int nframes) ;
int MRIsetResolution(MRI *mri, float xres, float yres, float zres) ;
int MRIsetTransform(MRI *mri, General_transform *transform) ;
/* correlation routines */
MRI *MRIxcorr(MRI *mri_ref, MRI *mri_in, MRI *mri_dst) ;
MRI *MRIxcorrWindow(MRI *mri_ref, MRI *mri_in,MRI *mri_dst,int window_size) ;
MRI *MRInxcorr(MRI *mri_ref, MRI *mri_in, MRI *mri_dst) ;
MRI *MRInxcorrWindow(MRI *mri_ref,MRI *mri_in,MRI *mri_dst,int window_size) ;
long MRIcorrelate(MRI *mri_ref, MRI *mri_in, int xoff, int yoff, int zoff) ;
int MRIpeak(MRI *mri, int *px, int *py, int *pz) ;
int MRIcompareHeaders(MRI const *mri1, MRI const *mri2) ;
MRI *MRIcopyHeader( const MRI *mri_src, MRI *mri_dst) ;
int MRIcopyPulseParameters(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIcopy(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) ;
int MRIboundingBox(MRI *mri, int thresh, MRI_REGION *region) ;
int MRIlabelBoundingBox(MRI *mri, int label, MRI_REGION *region) ;
int MRIfindApproximateSkullBoundingBox(MRI *mri, int thresh,
MRI_REGION *region) ;
int MRIboundingBoxNbhd(MRI *mri, int thresh, int wsize,MRI_REGION *region) ;
MRI *MRIsetBoundingBox(MRI *mri_template,
MRI_REGION *region,
double InVal,
double OutVal);
/* coordinate transforms */
MRI *MRItranslate(MRI *mri_src, MRI *mri_dst,
double dx, double dy, double dz) ;
MRI *MRIrotateX(MRI *mri_src, MRI *mri_dst, float x_angle) ;
MRI *MRIrotateY(MRI *mri_src, MRI *mri_dst, float y_angle) ;
MRI *MRIrotateZ(MRI *mri_src, MRI *mri_dst, float z_angle) ;
MRI *MRIrotate(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) ;
MRI *MRIscale(MRI *mri_src, MRI *mri_dst, float sx, float sy, float sz) ;
MRI *MRIaffine(MRI *mri_src, MRI *mri_dst, MATRIX *mA, MATRIX *mB) ;
MRI *MRIinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) ;
MRI *MRIlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *mA,
int InterpMethod);
MRI *MRIlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) ;
MRI *MRIapplyRASlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) ;
MRI *MRIapplyRASinverseLinearTransform(MRI *mri_src, MRI *mri_dst,
MATRIX *mA) ;
MRI *MRIapplyRASlinearTransformInterp(MRI *mri_src, MRI *mri_dst,
MATRIX *mA, int interpMethod) ;
MRI *MRIapplyRASinverseLinearTransformInterp(MRI *mri_src, MRI *mri_dst,
MATRIX *mA, int interpMethod) ;
int MRIinterpCode(const char *InterpString);
const char * MRIinterpString(int InterpCode);
MRI *MRIinterpolate(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIconfThresh(MRI *mri_src, MRI *mri_probs, MRI *mri_classes,
MRI *mri_dst,float thresh, int min_target,int max_target);
/* debugging */
int MRIdump(MRI *mri, FILE *fp) ;
int MRIdumpBuffer(MRI *mri, FILE *fp) ;
/* arithmetic operations */
double MRIrmsDifferenceNonzero(MRI *mri1, MRI *mri2) ;
MRI *MRIsubtract(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
MRI *MRIabsdiff(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
MRI *MRIadd(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
MRI *MRIaddScalar(MRI *mri_src, MRI *mri_dst, float scalar) ;
MRI *MRIaverage(MRI *mri_src, int dof, MRI *mri_dst) ;
MRI *MRIaddToFrame(MRI *mri_src, MRI *mri_to_add, MRI *mri_dst, int src_frame_no, int dst_frame_no) ;
MRI *MRIdivide(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
MRI *MRIdivideFrames(MRI *mri1, MRI *mri2, int frame1, int frame2, MRI *mri_dst) ;
MRI *MRImultiply(MRI *mri1, MRI *mri2, MRI *mri_dst) ;
MRI *MRIscaleAndMultiply(MRI *mri1, float scale, MRI *mri2, MRI *mri_dst) ;
MRI *MRIabs(MRI *mri, MRI *mri_dst) ;
MRI *MRIneg(MRI *mri_src, MRI *mri_dst);
MRI *MRIpos(MRI *mri_src, MRI *mri_dst);
MRI *MRIlinearScale(MRI *mri_src,
MRI *mri_dst,
float scale,
float offset,
int only_nonzer) ;
MRI *MRIscalarMul(MRI *mri_src, MRI *mri_dst, float scalar) ;
MRI *MRIscalarMulFrame(MRI *mri_src, MRI *mri_dst, float scalar, int frame) ;
void MRIrms(MRI *in, MRI *out);
/* filtering */
int MRIcpolvAllQuadrantsFilled(MRI *mri,
int x, int y, int z,int vertex,
int wsize) ;
MRI *MRIremoveIslands(MRI *mri_src, MRI*mri_dst, int wsize, int thresh) ;
MRI *MRIresegmentThinWMStrands(MRI *mri_src, MRI *mri_dst, int thickness);
MRI *MRIthickenThinWMStrands(MRI *mri_T1,
MRI *mri_src, MRI *mri_dst,
int thickness, int nsegments, float wm_hi) ;
MRI *MRIfindThinWMStrands(MRI *mri_src, MRI *mri_dst, int wsize);
MRI *MRIcentralPlaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst,
int wsize);
MRI *MRIplaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) ;
int MRIcpolvMaxWhiteAtVoxel(MRI *mri, int x, int y, int z, int wsize) ;
MRI *MRIpolvZscore(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) ;
MRI *MRIpolvNormalCurvature(MRI *mri_src, MRI *mri_dst, MRI *mri_polv,
int wsize) ;
MRI *MRIpolvMean(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) ;
MRI *MRIpolvMedian(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) ;
MRI *MRIpolvOrder(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize,
int thresh) ;
MRI *MRIpolvCount(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize,
int low_lim, int hi_lim) ;
MRI *MRIorderThreshold(MRI *mri_src, MRI *mri_dst, MRI *mri_order, int num) ;
MRI *MRIpolvMeanRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize,
MRI_REGION *region);
MRI *MRIpolvMedianRegion(MRI *mri_src, MRI *mri_dst,MRI *mri_polv,int wsize,
MRI_REGION *region);
MRI *MRIdivergence(MRI *mri_src, MRI *mri_divergence) ;
MRI *MRIlaplacian(MRI *mri_src, MRI *mri_laplacian);
MRI *MRIsobelFrame(MRI *mri_src, MRI *mri_grad, MRI *mri_mag, int frame) ;
MRI *MRIsobel(MRI *mri_src, MRI *mri_grad, MRI *mri_mag);
MRI *MRIxSobel(MRI *mri_src, MRI *mri_x, int frame) ;
MRI *MRIxSobelForAllTypes(MRI *mri_src, MRI *mri_x, int frame) ;
MRI *MRIySobel(MRI *mri_src, MRI *mri_y, int frame) ;
MRI *MRIySobelForAllTypes(MRI *mri_src, MRI *mri_y, int frame) ;
MRI *MRIzSobel(MRI *mri_src, MRI *mri_z, int frame) ;
MRI *MRIzSobelForAllTypes(MRI *mri_src, MRI *mri_z, int frame) ;
MRI *MRIsobelRegion(MRI *mri_src, MRI *mri_grad, int domag,
MRI_REGION *region);
MRI *MRIxSobelRegion(MRI *mri_src, MRI *mri_x, int frame,MRI_REGION *region);
MRI *MRIySobelRegion(MRI *mri_src, MRI *mri_y, int frame,MRI_REGION *region);
MRI *MRIzSobelRegion(MRI *mri_src, MRI *mri_z, int frame,MRI_REGION *region);
MRI *MRIreduce(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIreduce2D(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIreduceSlice(MRI *mri_src, MRI *mri_dst,
float *k, int len, int axis) ;
MRI *MRIreduceByte(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIconvolve1dFloat(MRI *mri_src, MRI *mri_dst,
float *k, int len, int axis,
int src_frame, int dst_frame);
MRI *MRIconvolve1dShort(MRI *mri_src, MRI *mri_dst, float *k, int len,
int axis, int src_frame, int dst_frame) ;
MRI *MRIconvolve1dInt(MRI *mri_src, MRI *mri_dst, float *k, int len,
int axis, int src_frame, int dst_frame) ;
MRI *MRIconvolve1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len,
int axis, int src_frame, int dst_frame) ;
MRI *MRIconvolve1d(MRI *mri_src, MRI *mri_dst, float *kernel,
int len, int axis, int src_frame, int dst_frame) ;
MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst,float *kernel,int len,int axis);
MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst,float *kernel,int len,
int axis);
double MRIrmsDiff(MRI *mri1, MRI *mri2) ;
MRI *MRIdiffuse(MRI *mri_src, MRI *mri_dst, double k,
int niter, int which, double slope) ;
MRI *MRIdiffuseCurvature(MRI *mri_src, MRI *mri_dst,
double A,int niter, double slope) ;
MRI *MRIdiffusePerona(MRI *mri_src, MRI *mri_dst,
double k, int niter,double slope);
MRI *MRIdirectionMap(MRI *mri_grad, MRI *mri_direction, int wsize);
MRI *MRIdirectionMapUchar(MRI *mri_grad, MRI *mri_direction, int wsize);
void MRIcalcCRASforSampledVolume(MRI *src, MRI *sampled,
double *pr, double *pa, double *ps);
void MRIcalcCRASforExtractedVolume(MRI *src, MRI *dst,
int x0, int y0, int z0,
int x1, int y1, int z1,
double *pr, double *pa, double *ps);
// 0 is the src extract position start
// 1 is the dst extracted region start
MRI *MRIsrcTransformedCentered(MRI *src, MRI *dst,
MATRIX *stod_voxtovox, int interp_method);
MRI *MRITransformedCenteredMatrix(MRI *src, MRI *orig_dst, MATRIX *m_L) ;
/* offset stuff */
MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction,
MRI *mri_dir);
MRI *MRIoffsetMagnitude(MRI *mri_src, MRI *mri_dst, int maxsteps) ;
MRI *MRIapplyOffset(MRI *mri_src, MRI *mri_dst, MRI *mri_offset) ;
/* it just copies the header info, not image data */
MRI *MRIclone( const MRI *mri_src, MRI *mri_dst );
MRI *MRIcloneDifferentType(MRI *mri_src, int type) ;
MRI *MRIcloneRoi(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIcloneBySpace(MRI *mri_src, int type, int nframes);
MRI *MRIthreshold(MRI *mri_src, MRI *mri_dst, float threshold) ;
MRI *MRIthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) ;
MRI *MRIupperthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) ;
MRI *MRIthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) ;
MRI *MRIupperthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) ;
MRI *MRIinvert(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIinvertContrast(MRI *mri_src, MRI *mri_dst, float threshold) ;
MRI *MRIbinarizeNoThreshold(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIbinarize(MRI *mri_src, MRI *mri_dst, float threshold,
float low_val, float hi_val) ;
MRI *MRIthresholdRangeInto(MRI *mri_src, MRI *mri_dst,
BUFTYPE low_val, BUFTYPE hi_val) ;
int MRIprincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues,
double *means, BUFTYPE theshold) ;
int MRIcenterOfMass(MRI *mri,double *means, BUFTYPE threshold) ;
int MRIbinaryPrincipleComponents(MRI *mri, MATRIX *mEvectors,
float *evalues,
double *means, BUFTYPE theshold) ;
int MRIprincipleComponentsRange(MRI *mri,
MATRIX *mEvectors,
float *evalues,
double *means,
float low_thresh,
float hi_thresh) ;
int MRIclear(MRI *mri_src) ;
/* these routines use trilinear interpolation */
MRI *MRIrotateX_I(MRI *mri_src, MRI *mri_dst, float x_angle) ;
MRI *MRIrotateY_I(MRI *mri_src, MRI *mri_dst, float y_angle) ;
MRI *MRIrotateZ_I(MRI *mri_src, MRI *mri_dst, float z_angle) ;
MRI *MRIrotate_I(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) ;
/* extraction routines */
MRI *MRIextract(MRI *mri_src, MRI *mri_dst,
int x0, int y0, int z0,
int dx, int dy, int dz) ;
MRI *MRIextractInto(MRI *mri_src, MRI *mri_dst,
int x0, int y0, int z0,
int dx, int dy, int dz,
int x1, int y1, int z1) ;
MRI *MRIextractIntoRegion(MRI *mri_src, MRI *mri_dst,
int x0, int y0, int z0,
MRI_REGION *region) ;
MRI *MRIextractRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *region) ;
MRI *MRIinsertRegion(MRI *regionvol, MRI_REGION *region, MRI *temp, MRI *out);
MRI *MRIextractPolvPlane(MRI *mri_src, MRI *mri_dst, MRI *mri_polv,
int wsize, int x, int y, int z);
MRI *MRIextractCpolv(MRI *mri_src, MRI *mri_dst, MRI *mri_polv,
int wsize, int x, int y, int z);
MRI *MRIextractCpolvCoords(MRI *mri_src, int *px, int *py, int *pz,
MRI *mri_polv, int x, int y,int z,int wsize);
MRI *MRIextractValues(MRI *mri_src, MRI *mri_dst, float min_val,
float max_val) ;
MRI *MRIwmfilter(MRI *mri_src, MRI *mri_cpolv, MRI *mri_dst,
float nslope, float pslope) ;
MRI *MRIorder(MRI *mri_src, MRI *mri_dst, int wsize, float pct) ;
#if 1
MRI *MRIremoveHoles(MRI *mri_src, MRI*mri_dst, int wsize, float pct,
int use_all) ;
#else
MRI *MRIremoveHoles(MRI *mri_src, MRI*mri_dst, int wsize, float pct) ;
#endif
MRI *MRInormalizeFrameVectorLength(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIcomputeFrameVectorLength(MRI *mri_src, MRI *mri_dst);
MRI *MRIcomputeFrameVectorL1Length(MRI *mri_src, MRI *mri_dst);
/* morphology */
MRI *MRImorph(MRI *mri_src, MRI *mri_dst, int which) ;
MRI *MRIsetEdges(MRI *in, double SetVal, MRI *out);
MRI *MRIerode(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIerodeNN(MRI *in, MRI *out, int NNDef, int ErodeEdges=0);
MRI *MRIerodeLabels(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIerodeThresh(MRI *mri_src, MRI *mri_intensity, double thresh,MRI *mri_dst) ;
MRI *MRIdilate6Thresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) ;
MRI *MRIdilateThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) ;
MRI *MRIerodeZero(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIerode2D(MRI *mri_src, MRI *mri_dst);
MRI *MRIerodeRegion(MRI *mri_src, MRI *mri_dst,int wsize,MRI_REGION *region);
MRI *MRIerodeSegmentation(MRI *seg, MRI *out, int nErodes, int nDiffThresh);
MRI *MRIdilateSegmentation(MRI *seg, MRI *out, int nDils, MRI *mask,
int maskframe, double maskthresh, int *pnchanges);
MRI *MRIdilate(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIdilateUchar(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIopen(MRI *mri_src, MRI *mri_dst) ;
MRI *MRIopenN(MRI *mri_src, MRI *mri_dst, int order) ;