pnlbwh / conversion Goto Github PK
View Code? Open in Web Editor NEWVarious mri conversion/modification scripts
License: Other
Various mri conversion/modification scripts
License: Other
In order to find NRRD affine transform, so far we have been making an assumption that the gradients are stacked along last axis, notice the [:3,:3] indexing below:
https://github.com/pnlbwh/conversion/blob/master/conversion/nifti_write.py#L57
Example header snippet where gradients are stacked along the 3rd axis:
space directions: (2,0,0) (0,2,0) (0,0,2) none
centerings: cell cell cell ???
kinds: space space space list
endian: little
encoding: gzip
space units: "mm" "mm" "mm"
space origin: (-127.0, -127.0, -72.0)
measurement frame: (1,0,0) (0,1,0) (0,0,1)
However, it could be stacked along any of the axes. Moreover, the assumption is anomalous with grad_axis
calculation where we do not make this simplification.
Example header snippet where gradients are stacked along the 1st axis:
space directions: none (-1.3672,0,0) (0,-1.3672,0) (0,0,2.7000000000000002)
kinds: list domain domain domain
endian: little
encoding: gzip
space origin: (171.68000000000001,211.58500000000001,-69.554599999999994)
measurement frame: (-1,0,0) (0,-1,0) (0,0,1)
It would be good to set --bvec an --bval as optimal parameters in nhdr_write.py, so when converting a 3D volume does not require these input parameters.
Regards,
Fan
When converting from nrrd to nii, the bvec and bval files are empty. The nifti file looks correct. Any suggestions?
Revise https://drive.google.com/file/d/10Z-qpGJugASmlx_un8M2KVOdFpYZtA9T/view
The symbols are hard to read and keep attention on.
The two lines can be combined to only one:
R= FFTsqrt @ F
R/=np.linalg.norm(R, axis=0)
to
R= np.linalg.inv(FFTsqrt) @ F
which is in fact more appropriate according to:
D. C. Alexander, C. Pierpaoli, P. J. Basser and J. C. Gee, "Spatial transformations of diffusion tensor magnetic resonance images," in IEEE Transactions on Medical Imaging, vol. 20, no. 11, pp. 1131-1139, Nov. 2001.
This is not a breaking change, rather just an optimization.
bvec averaging may not be correct, should be done based on eigen decomposition:
conversion/conversion/grad_avg.py
Lines 67 to 70 in 48f94ce
nifti_write.py
may need to throw an error if det(sform or qform)>0
https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FDT/FAQ#What_conventions_do_the_bvecs_use.3F
See the riddle below:
Rounded F, V has a 1
in (2,2)
position:
In [43]: F
Out[43]:
array([[-2. , 0. , 0. ],
[ 0. , 1.91565 , -0.574721],
[ 0. , 0.574721, 1.91565 ]])
In [44]: FFT= F @ F.T
In [46]: lam, V= np.linalg.eig(FFT)
In [47]: lam
Out[47]: array([4.00001915, 4.00001915, 4. ])
In [48]: V
Out[48]:
array([[ 0. , 0. , 1. ],
[ 0.70710678, 0.70710678, 0. ],
[ 0.70710678, -0.70710678, 0. ]])
In [49]: FFTsqrt= V @ np.diag(np.sqrt(lam)) @ V.T
In [50]: R= np.linalg.inv(FFTsqrt) @ F
In [51]: R
Out[51]:
array([[-1. , 0. , 0. ],
[ 0. , 0.95782271, -0.28735981],
[ 0. , 0.28735981, 0.95782271]])
Not-rounded F, V has a 1
in (0,0)
position:
In [60]: F=np.array([[-2. , -0.0000000000000004 , 0.00000000000000011],
...: [-0.0000000000000004 , 1.9156450033187866 , -0.5747210383415222 ],
...: [ 0. , 0.5747210383415222 , 1.9156450033187866 ]])
In [61]: FFT= F @ F.T
In [62]: lam, V= np.linalg.eig(FFT)
In [63]: lam
Out[63]: array([4. , 4.00000005, 4.00000005])
In [64]: V
Out[64]:
array([[ 1. , 0. , -0. ],
[ 0. , -0.83834991, -0.32552648],
[ 0. , -0.54513249, 0.94553292]])
In [66]: FFTsqrt= V @ np.diag(np.sqrt(lam)) @ V.T
In [68]: R= np.linalg.inv(FFTsqrt) @ F
In [69]: R
Out[69]:
array([[-1. , 0. , 0. ],
[-0. , 1.16671138, -0.51555329],
[-0. , 0.09508781, 0.86866142]])
Presence of non-significant digits many decimal points after cause the R to be different! UKF and dcm2niix both use column normalization to obtain rotation matrix. If finite strain assumption rotation is provided to UKF, then R-1 @ R does not become unity which results in incorrect tracts:
However, the presence of the non-significant digits is not an issue for not-rounded F
if column normalization is used to obtain R
.
https://github.com/pnlbwh/conversion/blob/master/setup.py#L9
needs to be hooked up to _version.py
Nifti1 has scl_slope and scl_inter. The equivalent attributes in the Nrrd are oldmin and oldmax. However, we don't have support for oldmin and oldmax in Pynrrd if they are present in intensity calibrated images (for relative intensity images, they are ignored).
In NIFTI-->NRRD conversion old_min and old_max are calculated as follows:
datatype= nifti1.header.datatype
scl_slope= nifti1.header.scl_slope
scl_inter= nifti1.header.scl_inter
oldmin=(datatype_min)*scl_slope + scl_inter
oldmax= (datatype_max)*scl_slope + scl_inter
NRRD voxels should be reported by recovering scl_slope and scl_inter from the NHDR header and then unquantizing NRRD voxels:
find scl_slope and scl_inter from above and
unquantized_data= quantized_data*scl_slope+scl_inter
Max might change e.g. HCP data upto 2000
np.set_printoptions
doesn't give us control over precision in string formatting.
Sylvain suggested rounding to only 5 decimals.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.