Skip to content

Commit 9fb5296

Browse files
committed
modified: TORTOISEV4/CMakeLists.txt
new file: src/tools/Combine3DImagesTo4D/Combine3DImagesTo4D.cxx new file: src/tools/CombineDWIs/combine_dwis_with_bmatrix.h new file: src/tools/import_bruker/ImportBruker.cxx new file: src/tools/import_bruker/bruker_anatomical_parser.cxx new file: src/tools/import_bruker/bruker_anatomical_parser.h new file: src/tools/import_bruker/bruker_parser.cxx new file: src/tools/import_bruker/bruker_parser.h new file: src/tools/import_bruker/convert_bruker.cxx new file: src/tools/import_bruker/convert_bruker.h new file: src/tools/import_bruker/convert_bruker_anatomical.cxx new file: src/tools/import_bruker/convert_bruker_anatomical.h new file: src/tools/import_bruker/import_bruker.cxx new file: src/tools/import_bruker/import_bruker_anatomical.cxx
1 parent 6e2d06c commit 9fb5296

16 files changed

+4132
-1
lines changed

TORTOISEV4/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SET(USEOPENMP 1)
88

99

1010
if ( NOT DEFINED USECUDA)
11-
SET(USECUDA 1)
11+
SET(USECUDA 0)
1212
endif()
1313
if ( NOT DEFINED USE_VTK)
1414
SET(USE_VTK 0)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <string>
2+
#include <vector>
3+
#include "defines.h"
4+
#include "../utilities/write_3D_image_to_4D_file.h"
5+
6+
7+
int main(int argc, char *argv[])
8+
{
9+
if(argc < 4)
10+
{
11+
std::cout<< "Usage: Combine3DImagesTo4D output_nifti_filename nifti1_filename nifti2_filename .......... niftiN_filename "<<std::endl;
12+
return EXIT_FAILURE;
13+
}
14+
15+
int Nimgs= argc-2;
16+
17+
for(int i=2;i< argc;i++)
18+
{
19+
ImageType3D::Pointer img = readImageD<ImageType3D>(argv[i]);
20+
21+
write_3D_image_to_4D_file<float>(img,argv[1],i-2,Nimgs);
22+
23+
}
24+
25+
26+
return EXIT_SUCCESS;
27+
28+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#ifndef __COMBINEDWISWITHBMATRIX_H
2+
#define __COMBINEDWISWITHBMATRIX_H
3+
4+
5+
#include "defines.h"
6+
#include "../utilities/write_3D_image_to_4D_file.h"
7+
#include "../utilities/extract_3Dvolume_from_4D.h"
8+
#include "../utilities/read_bmatrix_file.h"
9+
#include "../tools/TORTOISEBmatrixToFSLBVecs/tortoise_bmatrix_to_fsl_bvecs.h"
10+
11+
void CombineDWIsWithBMatrix(std::vector<std::string> nii_names, std::string output_name)
12+
{
13+
14+
int Nimgs= nii_names.size();
15+
16+
int tot_Nvols=0;
17+
for(int ni=0;ni<Nimgs;ni++)
18+
{
19+
std::string nii_name = nii_names[ni];
20+
itk::NiftiImageIO::Pointer myio = itk::NiftiImageIO::New();
21+
myio->SetFileName(nii_name);
22+
myio->ReadImageInformation();
23+
int Nvols= myio->GetDimensions(3);
24+
tot_Nvols+=Nvols;
25+
}
26+
27+
vnl_matrix<double> tot_Bmatrix(tot_Nvols,6);
28+
std::cout<<"Total volumes: "<< tot_Nvols<<std::endl;
29+
30+
int vols_so_far=0;
31+
for(int ni=0;ni<Nimgs;ni++)
32+
{
33+
std::string nii_name = nii_names[ni];
34+
ImageType4D::Pointer img = readImageD<ImageType4D>(nii_name) ;
35+
int Nvols = img->GetLargestPossibleRegion().GetSize()[3];
36+
37+
std::string bmtxt_name = nii_name.substr(0,nii_name.rfind(".nii"))+".bmtxt";
38+
39+
vnl_matrix<double> Bmatrix= read_bmatrix_file(bmtxt_name);
40+
tot_Bmatrix.update(Bmatrix,vols_so_far,0);
41+
42+
for(int v=0;v<Nvols;v++)
43+
{
44+
ImageType3D::Pointer vol = extract_3D_volume_from_4D(img,v);
45+
write_3D_image_to_4D_file<float>(vol,output_name,vols_so_far+v,tot_Nvols);
46+
}
47+
vols_so_far+=Nvols;
48+
}
49+
50+
std::string bmat_name= output_name.substr(0,output_name.rfind(".nii")) + ".bmtxt";
51+
std::string bvals_fname= output_name.substr(0,output_name.rfind(".nii")) + ".bvals";
52+
std::string bvecs_fname= output_name.substr(0,output_name.rfind(".nii")) + ".bvecs";
53+
std::ofstream outfile(bmat_name);
54+
outfile<<tot_Bmatrix;
55+
outfile.close();
56+
57+
vnl_matrix<double> bvecs(3,tot_Nvols);
58+
vnl_matrix<double> bvals= tortoise_bmatrix_to_fsl_bvecs(tot_Bmatrix, bvecs);
59+
60+
61+
std::ofstream bvecs_file(bvecs_fname.c_str());
62+
for(int i=0;i<3;i++)
63+
{
64+
for(int j=0;j<tot_Nvols;j++)
65+
{
66+
if(bvals(0,j)==0)
67+
bvecs_file<<"0 ";
68+
else
69+
bvecs_file<< bvecs(i,j)<< " ";
70+
}
71+
bvecs_file<<std::endl;
72+
}
73+
bvecs_file.close();
74+
75+
76+
std::ofstream bvals_file(bvals_fname.c_str());
77+
78+
79+
for(int j=0;j<tot_Nvols;j++)
80+
{
81+
bvals_file<< bvals(0,j)<< " ";
82+
}
83+
bvals_file.close();
84+
85+
86+
}
87+
88+
#endif

0 commit comments

Comments
 (0)