Skip to content

Commit 6c77917

Browse files
committed
Followed up with the required change
1 parent be6f31f commit 6c77917

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

WrapImage/nifti_wrapper.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import json
33
import os
44
import nibabel as nib
5+
from src.wrappers.OsipiBase import OsipiBase
6+
from utilities.data_simulation.GenerateData import GenerateData
57
import numpy as np
8+
import random
69

7-
def read_nifti_4d(input_file):
10+
def read_nifti_file(input_file):
811
"""
912
For reading the 4d nifti image
1013
"""
@@ -27,11 +30,11 @@ def read_json_file(json_file):
2730

2831
return json_data
2932

30-
def save_nifti_3d(data, output_file):
33+
def save_nifti_3d(data, output_file, **kwargs):
3134
"""
3235
For saving the 3d nifti images of the output of the algorithm
3336
"""
34-
output_img = nib.Nifti1Image(data, np.eye(4))
37+
output_img = nib.nifti1.Nifti1Image(data, np.eye(4), **kwargs)
3538
nib.save(output_img, output_file)
3639

3740
if __name__ == "__main__":
@@ -45,7 +48,7 @@ def save_nifti_3d(data, output_file):
4548

4649
try:
4750
# Read the 4D NIfTI file
48-
data = read_nifti_4d(args.input_file)
51+
data = read_nifti_file(args.input_file)
4952

5053
# Construct the full paths for the JSON, b-vector, and b-value files
5154
json_file = os.path.join(args.bids_dir, "dataset_description.json")
@@ -58,7 +61,20 @@ def save_nifti_3d(data, output_file):
5861
bvals = read_json_file(bval_file)
5962

6063
# 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+
6173
# 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")
6278

6379
except Exception as e:
6480
print(f"Error: {e}")

0 commit comments

Comments
 (0)