Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:freesurfer/freesurfer into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Greve committed Feb 21, 2022
2 parents 85bf17f + 6f21ef7 commit ecb154f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ if(NOT MINIMAL)
mri_fuse_intensity_images
mri_gca_ambiguous
mri_glmfit
mri_gradunwarp
mri_gtmpvc
mri_gtmseg
mri_hausdorff_dist
Expand Down Expand Up @@ -602,7 +603,6 @@ if(NOT MINIMAL)
mris_find_flat_regions
mris_flatten
mris_fwhm
mris_gradient_unwarp
mris_hausdorff_dist
mris_init_global_tractography
mris_interpolate_warp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
project(mris_gradient_unwarp)
project(mri_gradunwarp)

include_directories(${FS_INCLUDE_DIRS})

set(TARGET_EXE mris_gradient_unwarp)
set(TARGET_EXE mri_gradunwarp)

add_executable(${TARGET_EXE}
mris_gradient_unwarp.cpp)
mri_gradunwarp.cpp)

target_link_libraries(${TARGET_EXE} utils)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@
/* examples:
*
* unwarp at given crs (debugging)
* 1. mris_gradient_unwarp/mris_gradient_unwarp
* 1. mri_gradunwarp/mri_gradunwarp
* --gradcoeff $FS_TEST/gradunwarp/example/coeff_Sonata.grad
* --i $FS_TEST/gradunwarp/example/orig.mgz
* --crs 0,0,0
*
* unwarp for given ras (debugging)
* 2. mris_gradient_unwarp/mris_gradient_unwarp
* 2. mri_gradunwarp/mri_gradunwarp
* --gradcoeff $FS_TEST/gradunwarp/example/coeff_Sonata.grad
* --i $FS_TEST/gradunwarp/example/orig.mgz
* --ras 0.1,0.2,0.3
*
* create gradient unwarp transformation table
* 3. mris_gradient_unwarp/mris_gradient_unwarp
* 3. mri_gradunwarp/mri_gradunwarp
* --gradcoeff $FS_TEST/gradunwarp/example/coeff_Sonata.grad
* --i $FS_TEST/gradunwarp/example/orig.mgz
* --save_transtbl gradunwarp.m3z
* --nthreads 10
*
* transform given volume, save gradient unwarp transformation table
* 4. mris_gradient_unwarp/mris_gradient_unwarp
* 4. mri_gradunwarp/mri_gradunwarp
* --gradcoeff $FS_TEST/gradunwarp/example/coeff_Sonata.grad
* --i $FS_TEST/gradunwarp/example/orig.mgz
* --o orig.unwarped.cubic.mgz --interp cubic --unwarpvol
* --save_transtbl gradunwarp.m3z
* --nthreads 10
*
* transform given volume using input gradient unwarp transformation table
* 5. mris_gradient_unwarp/mris_gradient_unwarp
* 5. mri_gradunwarp/mri_gradunwarp
* --load_transtbl $FS_TEST/gradunwarp/transtbl/savetbl/gradunwarp.m3z
* --i $FS_TEST/gradunwarp/example/orig.mgz
* --o orig.unwarped.cubic.mgz --interp cubic --unwarpvol
Expand Down Expand Up @@ -118,7 +118,7 @@ int main(int argc, char *argv[])

interpcode = MRIinterpCode(interpmethod);

nargs = handleVersionOption(argc, argv, "mris_gradient_unwarp");
nargs = handleVersionOption(argc, argv, "mri_gradunwarp");
if (nargs && argc - nargs == 1) exit (0);
argc -= nargs;
cmdline = argv2cmdline(argc,argv);
Expand Down
41 changes: 39 additions & 2 deletions mris_find_flat_regions/mris_find_flat_regions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "version.h"
#include "label.h"
#include "mri_identify.h"

#include "colortab.h"

int main(int argc, char *argv[]) ;

Expand All @@ -41,6 +41,7 @@ static void print_version(void) ;

const char *Progname ;

static int segment_rois = 0 ;
static float thresh = 0.99 ;

int
Expand Down Expand Up @@ -88,9 +89,40 @@ main(int argc, char *argv[]) {
v->val = 1 ;
}

if (mri_identify(wfile_name) == MGH_LABEL_FILE)
if (segment_rois)
{
int nlabels, lno, num, vno ;
LABEL **labels ;

MRISthresholdValIntoMarked(mris, thresh) ;
MRISsegmentMarked(mris, &labels, &nlabels, 1) ;
printf("%d labels total\n", nlabels) ;
for (num = lno = 0 ; lno < nlabels ; lno++)
{
if (labels[lno]->n_points >= segment_rois)
{
if (num == 0)
printf("vertex %d gets annotation %d\n", labels[lno]->lv[0].vno, num+1);
for (vno = 0 ; vno < labels[lno]->n_points ; vno++)
{
mris->vertices[labels[lno]->lv[vno].vno].annotation = num+1 ;
}

char fname[STRLEN] ;
sprintf(fname, "flat%3.3d.label", num) ;
num++ ;
//LabelWrite(labels[lno], fname) ;
}
}
printf("%d labels found. Writing annotation to %s\n", num, wfile_name) ;
mris->ct = CTABalloc(num+1) ;
CTABrandom(mris->ct) ;
MRISwriteAnnotation(mris, wfile_name) ;
}
else if (mri_identify(wfile_name) == MGH_LABEL_FILE)
{
LABEL *area ;

area = LabelFromSurface(mris, VERTEX_VALS, .9) ;
LabelWrite(area, wfile_name) ;
}
Expand All @@ -117,6 +149,11 @@ get_option(int argc, char *argv[]) {
else if (!stricmp(option, "-version"))
print_version() ;
else switch (toupper(*option)) {
case 'S':
segment_rois = atoi(argv[2]) ;
nargs = 1 ;
printf("segmenting surface into ROIs with at least %d vertices\n", segment_rois) ;
break ;
case '?':
case 'U':
print_usage() ;
Expand Down
37 changes: 20 additions & 17 deletions utils/mriio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static MRI *ximgRead(const char *fname, int read_volume);
static MRI *nifti1Read(const char *fname, int read_volume);
static int nifti1Write(MRI *mri, const char *fname);
static MRI *niiRead(const char *fname, int read_volume);
static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct);
static MRI *niiReadFromMriFsStruct(MRIFSSTRUCT *mrifsStruct);
static int niiWrite(MRI *mri, const char *fname);
static int itkMorphWrite(MRI *mri, const char *fname);
static int niftiQformToMri(MRI *mri, struct nifti_1_header *hdr);
Expand Down Expand Up @@ -687,7 +687,7 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int
if (mrifsStruct == NULL)
return NULL;

mri = niiRead3(mrifsStruct);
mri = niiReadFromMriFsStruct(mrifsStruct);
if (mri != NULL && mri->ti < 0)
mri->ti = 0;

Expand All @@ -705,7 +705,7 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int
if (mrifsStruct == NULL)
return NULL;

mri = niiRead3(mrifsStruct);
mri = niiReadFromMriFsStruct(mrifsStruct);

free(mrifsStruct->imgM);
free(mrifsStruct->tdti);
Expand Down Expand Up @@ -8792,12 +8792,15 @@ static MRI *niiRead(const char *fname, int read_volume)


/*------------------------------------------------------------------
niiRead3() - note: there are also nifti1Read() and niiRead(). Make sure to
niiReadFromMriFsStruct() - note: there are also nifti1Read() and niiRead(). Make sure to
edit all. Automatically detects whether an input is Ico7
and reshapes.
This function is used with DICOMRead3().
DICOMRead3() read/parse dicom files using dcm2niix_fswrapper.
MRIFSSTRUCT holds the parsing output from dcm2niix, which contains nifti header,
image data, acqusition parameters, and bvecs. See nii_dicom_batch.h for details.
-----------------------------------------------------------------*/
static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)
static MRI *niiReadFromMriFsStruct(MRIFSSTRUCT *mrifsStruct)
{
MRI *mri, *mritmp;
int nslices;
Expand All @@ -8816,21 +8819,21 @@ static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)
swapped_flag = TRUE;
swap_nifti_1_header(hdr);
if (hdr->dim[0] < 1 || hdr->dim[0] > 7) {
ErrorReturn(NULL, (ERROR_BADFILE, "niiRead3(): bad number of dimensions (%hd)", hdr->dim[0]));
ErrorReturn(NULL, (ERROR_BADFILE, "niiReadFromMriFsStruct(): bad number of dimensions (%hd)", hdr->dim[0]));
}
}

if (memcmp(hdr->magic, NII_MAGIC, 4) != 0) {
ErrorReturn(NULL, (ERROR_BADFILE, "niiRead3(): bad magic number"));
ErrorReturn(NULL, (ERROR_BADFILE, "niiReadFromMriFsStruct(): bad magic number"));
}

// if (hdr.dim[0] != 2 && hdr.dim[0] != 3 && hdr.dim[0] != 4){
if (hdr->dim[0] < 1 || hdr->dim[0] > 5) {
ErrorReturn(NULL, (ERROR_UNSUPPORTED, "niiRead3(): %hd dimensions; unsupported", hdr->dim[0]));
ErrorReturn(NULL, (ERROR_UNSUPPORTED, "niiReadFromMriFsStruct(): %hd dimensions; unsupported", hdr->dim[0]));
}

if (hdr->datatype == DT_NONE || hdr->datatype == DT_UNKNOWN) {
ErrorReturn(NULL, (ERROR_UNSUPPORTED, "niiRead3(): unknown or no data type; bailing out"));
ErrorReturn(NULL, (ERROR_UNSUPPORTED, "niiReadFromMriFsStruct(): unknown or no data type; bailing out"));
}
if (hdr->dim[4] == 0) {
printf("WARNING: hdr->dim[4] = 0 (nframes), setting to 1\n");
Expand All @@ -8848,7 +8851,7 @@ static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)
space_units_factor = 1.0;
}
else
ErrorReturn(NULL, (ERROR_BADFILE, "niiRead3(): unknown space units %d", space_units));
ErrorReturn(NULL, (ERROR_BADFILE, "niiReadFromMriFsStruct(): unknown space units %d", space_units));

time_units = XYZT_TO_TIME(hdr->xyzt_units);
if (time_units == NIFTI_UNITS_SEC)
Expand All @@ -8871,7 +8874,7 @@ static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)
hdr->slice_code != NIFTI_SLICE_ALT_INC && hdr->slice_code != NIFTI_SLICE_ALT_DEC &&
hdr->slice_code != NIFTI_SLICE_ALT_INC2 && hdr->slice_code != NIFTI_SLICE_ALT_DEC2) {
ErrorReturn(
NULL, (ERROR_UNSUPPORTED, "niiRead3(): unsupported slice timing pattern %d", hdr->slice_code));
NULL, (ERROR_UNSUPPORTED, "niiReadFromMriFsStruct(): unsupported slice timing pattern %d", hdr->slice_code));
}
}

Expand All @@ -8883,7 +8886,7 @@ static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)
// put extra dims in frames
if (hdr->dim[0] > 4 && hdr->dim[5] > 0) nslices *= hdr->dim[5];
if (Gdiag_no > 0)
printf("niiRead3(): hdr->dim %d %d %d %d %d %d\n",
printf("niiReadFromMriFsStruct(): hdr->dim %d %d %d %d %d %d\n",
hdr->dim[0],
hdr->dim[1],
hdr->dim[2],
Expand Down Expand Up @@ -8934,19 +8937,19 @@ static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)
else if (hdr->datatype == DT_DOUBLE) {
fs_type = MRI_FLOAT;
bytes_per_voxel = 8;
printf("niiRead3(): detected input as 64 bit double, reading in as 32 bit float\n");
printf("niiReadFromMriFsStruct(): detected input as 64 bit double, reading in as 32 bit float\n");
}
#if 0 // MRI_RBG not support in mghWrite
else if (hdr->datatype == DT_RGB) {
fs_type = MRI_UCHAR; //MRI_RGB;
bytes_per_voxel = 3;
printf("niiRead3(): DT_RGB, MRI_RGB\n");
printf("niiReadFromMriFsStruct(): DT_RGB, MRI_RGB\n");
}
#endif
else {
ErrorReturn(
NULL,
(ERROR_UNSUPPORTED, "niiRead3(): unsupported datatype %d (with scl_slope = 0)", hdr->datatype));
(ERROR_UNSUPPORTED, "niiReadFromMriFsStruct(): unsupported datatype %d (with scl_slope = 0)", hdr->datatype));
}
}
else {
Expand All @@ -8956,7 +8959,7 @@ static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)
hdr->datatype != DT_UINT32) {
ErrorReturn(
NULL,
(ERROR_UNSUPPORTED, "niiRead3(): unsupported datatype %d (with scl_slope != 0)", hdr->datatype));
(ERROR_UNSUPPORTED, "niiReadFromMriFsStruct(): unsupported datatype %d (with scl_slope != 0)", hdr->datatype));
}
fs_type = MRI_FLOAT;
bytes_per_voxel = 0; /* set below -- avoid the compiler warning */
Expand Down Expand Up @@ -9288,7 +9291,7 @@ static MRI *niiRead3(MRIFSSTRUCT *mrifsStruct)

return (mri);

} /* end niiRead3() */
} /* end niiReadFromMriFsStruct() */

/*------------------------------------------------------------------
niiWrite() - note: there is also an nifti1Write(). Make sure to
Expand Down

0 comments on commit ecb154f

Please sign in to comment.