2
2
import json
3
3
import os
4
4
import nibabel as nib
5
+ from src .wrappers .OsipiBase import OsipiBase
6
+ from utilities .data_simulation .GenerateData import GenerateData
5
7
import numpy as np
8
+ import random
6
9
7
- def read_nifti_4d (input_file ):
10
+ def read_nifti_file (input_file ):
8
11
"""
9
12
For reading the 4d nifti image
10
13
"""
@@ -27,11 +30,11 @@ def read_json_file(json_file):
27
30
28
31
return json_data
29
32
30
- def save_nifti_3d (data , output_file ):
33
+ def save_nifti_3d (data , output_file , ** kwargs ):
31
34
"""
32
35
For saving the 3d nifti images of the output of the algorithm
33
36
"""
34
- output_img = nib .Nifti1Image (data , np .eye (4 ))
37
+ output_img = nib .nifti1 . Nifti1Image (data , np .eye (4 ), ** kwargs )
35
38
nib .save (output_img , output_file )
36
39
37
40
if __name__ == "__main__" :
@@ -45,7 +48,7 @@ def save_nifti_3d(data, output_file):
45
48
46
49
try :
47
50
# Read the 4D NIfTI file
48
- data = read_nifti_4d (args .input_file )
51
+ data = read_nifti_file (args .input_file )
49
52
50
53
# Construct the full paths for the JSON, b-vector, and b-value files
51
54
json_file = os .path .join (args .bids_dir , "dataset_description.json" )
@@ -58,7 +61,20 @@ def save_nifti_3d(data, output_file):
58
61
bvals = read_json_file (bval_file )
59
62
60
63
# Pass additional arguments to the algorithm
64
+ rng = np .random .RandomState (42 )
65
+ fit = OsipiBase (algorithm = args .algorithm )
66
+ S0 = 1
67
+ gd = GenerateData (rng = rng )
68
+ D = data ["D" ]
69
+ f = data ["f" ]
70
+ Dp = data ["Dp" ]
71
+ # signal = gd.ivim_signal(D, Dp, f, S0, bvals, SNR, rician_noise)
72
+
61
73
# Passing the values to the selectect algorithm and saving it
74
+ [f_fit , Dp_fit , D_fit ] = fit .osipi_fit (signal , bvals )
75
+ save_nifti_3d (f_fit , "f.nii.gz" )
76
+ save_nifti_3d (Dp_fit , "dp.nii.gz" )
77
+ save_nifti_3d (D_fit , "d.nii.gz" )
62
78
63
79
except Exception as e :
64
80
print (f"Error: { e } " )
0 commit comments