-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code and data for simulation of brain phantom #9
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Code for generating ivim phantoms of the brain | ||
|
||
Two sets of ground truth data are used for simulation: | ||
- Simulation in the diffusive regime (IVIM parameters D, f and D*): reference values from Ryghög et al. 2014 and b-values from Federau et al. 2012 | ||
- Simulation in the ballistic regime (IVIM parameters D, f and vd): reference values and sequence parameters from Ahlgren et al. 2016 | ||
|
||
The segmentation used by the simulations is the ICBM 2009a nonlinear symmetric 3T atlas (https://nist.mni.mcgill.ca/icbm-152-nonlinear-atlases-2009/), the same as in e.g. ASLDRO (https://asldro.readthedocs.io/en/stable/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 10 20 30 40 50 60 70 80 90 100 120 140 160 180 200 10 20 30 40 50 60 70 80 90 100 120 140 160 180 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.471 0.666 0.816 0.942 1.054 1.154 1.247 1.333 1.414 1.490 1.632 1.763 1.885 1.999 2.107 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 10 20 30 40 80 110 140 170 200 300 400 500 600 700 800 900 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 10 20 30 40 50 60 70 80 90 100 120 140 160 180 200 10 20 30 40 50 60 70 80 90 100 120 140 160 180 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.471 0.666 0.816 0.942 1.054 1.154 1.247 1.333 1.414 1.490 1.632 1.763 1.885 1.999 2.107 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
import numpy as np | ||
|
||
# Data from Ahlgren et al 2016 NMRinBiomed | ||
Delta = 7.5e-3 # 7.5 ms | ||
delta = 7.3e-3 # 7.3 ms | ||
|
||
# For DDE sequence we have | ||
# b = 2y^2G^2d^2(D-d/3), c = 2yGdD => c = sqrt(b 2D^2/(D-d/3)) | ||
bval_file = os.path.join(os.path.dirname(__file__),'ballistic.bval') | ||
b = np.loadtxt(bval_file) | ||
c = np.sqrt(b*2*Delta**2/(Delta-delta/3)) | ||
c[1:(c.size-1)//2+1] = 0 # flow compensated => c = 0 | ||
cval_file = bval_file.replace('bval','cval') | ||
np.savetxt(cval_file,c,fmt='%.3f',newline=' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"D":[1.2e-3,0.98e-3,3e-3], | ||
"f":[0.0243,0.0164,0], | ||
"vd":[1.71,1.73,0], | ||
"Db":1.75e-3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 10 20 30 40 80 110 140 170 200 300 400 500 600 700 800 900 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"D":[0.81e-3,0.86e-3,3e-3], | ||
"f":[0.044,0.033,0], | ||
"Dstar":[84e-3,76e-3,0] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import shutil | ||
import json | ||
import numpy as np | ||
import nibabel as nib | ||
from scipy.ndimage import zoom | ||
|
||
regime = 'diffusive'#'ballistic' # | ||
snr = 200 | ||
resolution = [3,3,3] | ||
|
||
folder = os.path.dirname(__file__) | ||
|
||
# Ground truth | ||
nii = nib.load(os.path.join(folder,'ground_truth','hrgt_icbm_2009a_nls_3t.nii.gz')) | ||
segmentation = np.squeeze(nii.get_fdata()[...,-1]) | ||
|
||
with open(os.path.join(folder,'ground_truth',regime+'_groundtruth.json'), 'r') as f: | ||
ivim_pars = json.load(f) | ||
S0 = 1 | ||
|
||
# Sequence parameters | ||
bval_file = os.path.join(folder,'ground_truth',regime+'.bval') | ||
b = np.loadtxt(bval_file) | ||
if regime == 'ballistic': | ||
cval_file = bval_file.replace('bval','cval') | ||
c = np.loadtxt(cval_file) | ||
|
||
# Calculate signal | ||
S = np.zeros(list(np.shape(segmentation))+[b.size]) | ||
|
||
if regime == 'ballistic': | ||
Db = ivim_pars["Db"] | ||
for i,(D,f,vd) in enumerate(zip(ivim_pars["D"],ivim_pars["f"],ivim_pars["vd"])): | ||
S[segmentation==i+1,:] = S0*((1-f)*np.exp(-b*D)+f*np.exp(-b*Db-c**2*vd**2)) | ||
else: | ||
for i,(D,f,Dstar) in enumerate(zip(ivim_pars["D"],ivim_pars["f"],ivim_pars["Dstar"])): | ||
S[segmentation==i+1,:] = S0*((1-f)*np.exp(-b*D)+f*np.exp(-b*Dstar)) | ||
|
||
# Resample to suitable resolution | ||
im = zoom(S,np.append(np.diag(nii.affine)[:3]/np.array(resolution),1),order=1) | ||
sz = im.shape | ||
|
||
# Add noise | ||
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]))) | ||
|
||
# Save as image and sequence parameters | ||
nii_out = nib.Nifti1Image(im_noise,np.eye(4)) | ||
base_name = os.path.join(folder,'data','{}_snr{}'.format(regime,snr)) | ||
nib.save(nii_out,base_name+'.nii.gz') | ||
shutil.copyfile(bval_file,base_name+'.bval') | ||
if regime == 'ballistic': | ||
shutil.copyfile(cval_file,base_name+'.cval') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check if the
regime
is strictly eitherdiffusive
orballistic
. Right now a simple misspelling likebalistic
would actually generate the diffusive phantom.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I use predefined string variables now instead. Robust enough?