Skip to content

Commit be85ee3

Browse files
Merge pull request #161 from OSIPI/preproc-main
Preproc-main into main
2 parents 7c84913 + 640e62e commit be85ee3

160 files changed

Lines changed: 1180 additions & 39 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ coverage.xml
4040
*.pyc
4141
phantoms/MR_XCAT_qMRI/*.json
4242
phantoms/MR_XCAT_qMRI/*.txt
43+
phantoms/brain/data/*.nii.gz
44+
phantoms/brain/ground_truth/*.nii.gz
4345
tests/IVIMmodels/unit_tests/models
4446
models
47+
temp
48+
.vscode
49+
.env

doc/code_contributions_record.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - trust region
2929
IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - segmented algorithm,TCML_TechnionIIT,TF2.4_IVIM-MRI_CodeCollection/src/original/TCML_TechnionIIT/SUPER-IVIM-DC,Noam Korngut/Elad Rotman/Onur Afacan Sila Kurugol/Yael Zaffrani-Reznikov/Shira Nemirovsky-Rotman/Simon Warfield/Moti Freiman,TCML Technion IIT,super_ivim_dc.source.Classsic_ivim_fit.IVIM_fit_sls,https://doi.org/10.1007/978-3-031-16434-7_71,TCML_TechnionIIT_lsqSLS
3030
IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - Levenberg Marquart lsq algorithm initialized with segmented fitting,TCML_TechnionIIT,TF2.4_IVIM-MRI_CodeCollection/src/original/TCML_TechnionIIT/SUPER-IVIM-DC,Noam Korngut/Elad Rotman/Onur Afacan Sila Kurugol/Yael Zaffrani-Reznikov/Shira Nemirovsky-Rotman/Simon Warfield/Moti Freiman,TCML Technion IIT,super_ivim_dc.source.Classsic_ivim_fit.IVIM_fit_sls_lm,https://doi.org/10.1007/978-3-031-16434-7_71,TCML_TechnionIIT_lsq_sls_lm
3131
IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - trust region lsq algorithm initialized with segmented fitting,TCML_TechnionIIT,TF2.4_IVIM-MRI_CodeCollection/src/original/TCML_TechnionIIT/SUPER-IVIM-DC,Noam Korngut/Elad Rotman/Onur Afacan Sila Kurugol/Yael Zaffrani-Reznikov/Shira Nemirovsky-Rotman/Simon Warfield/Moti Freiman,TCML Technion IIT,super_ivim_dc.source.Classsic_ivim_fit.IVIM_fit_sls_trf,https://doi.org/10.1007/978-3-031-16434-7_71,TCML_TechnionIIT_lsq_sls_trf
32-
IVIM,Fitting,Segmented linear fitting,Consensus algorithm,TF_reference,TF2.4_IVIM-MRI_CodeCollection/src/original/TF_reference/,Ben Neijndorff/OSIPI taskforce 2.4,OSIPI,segmented_IVIMfit,tba,TF_reference_IVIMfit
32+
IVIM,Fitting,Segmented linear fitting,Consensus algorithm,TF_reference,TF2.4_IVIM-MRI_CodeCollection/src/original/TF_reference/,Ben Neijndorff/OSIPI taskforce 2.4,OSIPI,segmented_IVIMfit,tba,TF_reference_IVIMfit
33+
IVIM,Preprocessing,Full pipeline,Brain pipeline,EP_GU,TF2.4_IVIM-MRI_CodeCollection/src/original/EP_GU,Elina Petersson,University of Gothenburg,brain_preproc,tba,

src/original/DK_OGC_AmsterdamUMC/__init__.py renamed to phantoms/__init__.py

File renamed without changes.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
2+
"tissues": ["WM","GM","CSF"],
23
"D":[1.2e-3,0.98e-3,3e-3],
34
"f":[0.0243,0.0164,0],
45
"vd":[1.71,1.73,0],
5-
"Db":1.75e-3
6+
"Db":1.75e-3,
7+
"T1":[1.0, 1.5, 3.4],
8+
"T2":[0.046,0.068,0.45]
69
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2+
"tissues": ["WM","GM","CSF"],
23
"D":[0.81e-3,0.86e-3,3e-3],
34
"f":[0.044,0.033,0],
4-
"Dstar":[84e-3,76e-3,0]
5-
}
5+
"Dstar":[84e-3,76e-3,0],
6+
"T1":[1.0, 1.5, 3.4],
7+
"T2":[0.046,0.068,0.45]
8+
}

phantoms/brain/sim_brain_phantom.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@
66
from scipy.ndimage import zoom
77
from utilities.data_simulation.Download_data import download_data
88

9-
if __name__ == "__main__":
9+
DIFFUSIVE_REGIME = 'diffusive'
10+
BALLISTIC_REGIME = 'ballistic'
11+
12+
def simulate_brain_phantom(regime=DIFFUSIVE_REGIME, snr=100, sim_relaxation=True, TE=60e-3, TR=5, resolution=[3,3,3]):
13+
'''
14+
Simulation parameters can be set by changing the default values of the function arguments.
15+
The default values are chosen to be suitable for a diffusive regime phantom, but can be changed to simulate a ballistic regime phantom as well.
16+
The simulated image is saved in phantoms/brain/data with the name 'diffusive_sn{snr}.nii.gz' or 'ballistic_sn{snr}.nii.gz' depending on the regime.
17+
The corresponding bvals and cvals (if applicable) are also saved in the same folder.
18+
19+
regime: 'diffusive' or 'ballistic' to choose the type of phantom to simulate
20+
snr: signal-to-noise ratio of the simulated image
21+
sim_relaxation: whether to simulate T1 and T2 relaxation effects in the signal
22+
TE: echo time in seconds
23+
TR: repetition time in seconds
24+
resolution: voxel size in mm
25+
'''
1026
download_data()
1127

12-
DIFFUSIVE_REGIME = 'diffusive'
13-
BALLISTIC_REGIME = 'ballistic'
1428

1529
folder = os.path.dirname(__file__)
1630

17-
###########################
18-
# Simulation parameters #
19-
regime = DIFFUSIVE_REGIME
20-
snr = 200
21-
resolution = [3,3,3]
22-
# #
23-
###########################
24-
25-
2631
# Ground truth
2732
nii = nib.load(os.path.join(os.path.split(os.path.split(folder)[0])[0],'download','Phantoms','brain','ground_truth','hrgt_icbm_2009a_nls_3t.nii.gz'))
2833
segmentation = np.squeeze(nii.get_fdata()[...,-1])
@@ -40,20 +45,30 @@
4045

4146
# Calculate signal
4247
S = np.zeros(list(np.shape(segmentation))+[b.size])
43-
48+
print(ivim_pars)
4449
if regime == BALLISTIC_REGIME:
4550
Db = ivim_pars["Db"]
46-
for i,(D,f,vd) in enumerate(zip(ivim_pars["D"],ivim_pars["f"],ivim_pars["vd"])):
51+
for i,(D,f,vd,T1,T2) in enumerate(zip(ivim_pars["D"],ivim_pars["f"],ivim_pars["vd"],ivim_pars["T1"],ivim_pars["T2"])):
4752
S[segmentation==i+1,:] = S0*((1-f)*np.exp(-b*D)+f*np.exp(-b*Db-c**2*vd**2))
53+
if sim_relaxation:
54+
S[segmentation==i+1,:] *= np.exp(-TE/T2)*(1-np.exp(-TR/T1))
4855
else:
49-
for i,(D,f,Dstar) in enumerate(zip(ivim_pars["D"],ivim_pars["f"],ivim_pars["Dstar"])):
56+
for i,(D,f,Dstar,T1,T2) in enumerate(zip(ivim_pars["D"],ivim_pars["f"],ivim_pars["Dstar"],ivim_pars["T1"],ivim_pars["T2"])):
5057
S[segmentation==i+1,:] = S0*((1-f)*np.exp(-b*D)+f*np.exp(-b*Dstar))
58+
if sim_relaxation:
59+
S[segmentation==i+1,:] *= np.exp(-TE/T2)*(1-np.exp(-TR/T1))
5160

5261
# Resample to suitable resolution
5362
im = zoom(S,np.append(np.diag(nii.affine)[:3]/np.array(resolution),1),order=1)
5463
sz = im.shape
5564

56-
# Add noise
65+
# Save image without noise for reference
66+
nii_out = nib.Nifti1Image(im,np.eye(4))
67+
base_name = os.path.join(folder,'data','{}_reference'.format(regime,snr))
68+
nib.save(nii_out,base_name+'.nii.gz')
69+
shutil.copyfile(bval_file,base_name+'.bval')
70+
71+
# Add Rician noise
5772
im_noise = np.abs(im + S0/snr*(np.random.randn(sz[0],sz[1],sz[2],sz[3])+1j*np.random.randn(sz[0],sz[1],sz[2],sz[3])))
5873

5974
# Save as image and sequence parameters
@@ -62,4 +77,14 @@
6277
nib.save(nii_out,base_name+'.nii.gz')
6378
shutil.copyfile(bval_file,base_name+'.bval')
6479
if regime == BALLISTIC_REGIME:
65-
shutil.copyfile(cval_file,base_name+'.cval')
80+
shutil.copyfile(cval_file,base_name+'.cval')
81+
82+
# Resample and save segmentation
83+
segmentation = zoom(segmentation,np.diag(nii.affine)[:3]/np.array(resolution),order=0)
84+
nii_out = nib.Nifti1Image(segmentation,np.eye(4))
85+
base_name = os.path.join(folder,'data','{}_snr{}_mask'.format(regime,snr))
86+
nib.save(nii_out,base_name+'.nii.gz')
87+
88+
89+
if __name__ == "__main__":
90+
simulate_brain_phantom()

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ markers =
33
slow: marks tests as slow (deselect with '-m "not slow"')
44
addopts =
55
-m 'not slow'
6+
--ignore-glob=**/wip_*.py
67
testpaths = tests
78
filterwarnings =
89
ignore::Warning

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ sphinx_rtd_theme
1818
pytest-json-report
1919
statsmodels
2020
ivimnet
21-
nlopt
21+
nlopt
22+
nipype
23+
itk
24+
#ivim-mri

src/original/ASD_MemorialSloanKettering/MRI-QAMPER_IVIM/.gitignore renamed to src/original/fitting/ASD_MemorialSloanKettering/MRI-QAMPER_IVIM/.gitignore

File renamed without changes.

src/original/ASD_MemorialSloanKettering/MRI-QAMPER_IVIM/IVIM_standard_bcin.m renamed to src/original/fitting/ASD_MemorialSloanKettering/MRI-QAMPER_IVIM/IVIM_standard_bcin.m

File renamed without changes.

0 commit comments

Comments
 (0)