GithubHelp home page GithubHelp logo

conversion's People

Contributors

hjmjohnson avatar tashrifbillah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

conversion's Issues

Omit none row from space directions

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)

[Optimization] Use FFT^(-0.5)

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:
image

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.

Finite strain assumption?

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:

image

However, the presence of the non-significant digits is not an issue for not-rounded F if column normalization is used to obtain R.

oldmin and oldmax required for NHDRs pertinent to intensity calibrated NIFTI images

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

Precision control

np.set_printoptions doesn't give us control over precision in string formatting.

Sylvain suggested rounding to only 5 decimals.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.