Skip to content
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

Philips DWI conversion to NRRD and NIFTI #612

Closed
hjmjohnson opened this issue Jun 16, 2022 · 5 comments
Closed

Philips DWI conversion to NRRD and NIFTI #612

hjmjohnson opened this issue Jun 16, 2022 · 5 comments

Comments

@hjmjohnson
Copy link

hjmjohnson commented Jun 16, 2022

Describe the bug

Gradient directions have different interpretations for NIFTI and NRRD converted files, but have the same numerical values.

To reproduce

For data collected for a single shell DWI sequence on a :

DICOM_0008_0070_Manufacturer:=Philips Medical Systems
DICOM_0008_1090_ManufacturerModelName:=Achieva
DICOM_0018_0022_ScanOptions:=FS
DICOM_0018_0023_MRAcquisitionType:=2D
DICOM_0018_0087_MagneticFieldStrength:=3
DICOM_0018_1020_SoftwareVersions:=2.6.1\2.6.1.0

run dcm2niix -e n ...
run dcm2niix -e y ...

and compare the gradients that are written to files.

Expected behavior

Gradient direction values are encoded differently in nhdr and bvec files, so they should have different numerical values. The nifti variant has an implied identity measurement frame. The nhdr file can have a non-identity measurement frame. If the measurement frame in the nhdr file is not identity, then the values in the bvec file should be different from those stored in the nhdr file.

The first gradient (second column) of values stored for fsl format bvec file (Implied identity measurement frame).

                                            0.198366                     0.155057                       0.967785

First gradient stored in NRRD format header:

measurement frame: (-0.999163,-0.0409067,1.47627e-05) (-0.0407948,0.996402,-0.0742841) (-0.00302401,0.0742225,0.997236)
DWMRI_gradient_0001:=0.19836626946926117 0.15505728125572205 0.96778517961502075

Version

dcm2niix -v
Chris Rorden's dcm2niiX version v1.0.20211006 (JP2:OpenJPEG) GCC9.3.0 x86-64 (64-bit Linux)
v1.0.20211006

(same results from today's development build)

Troubleshooting

I reviewed content on https://www.na-mic.org/wiki/NAMIC_Wiki:DTI:Nrrd_format.

https://www.na-mic.org/wiki/File:Coords-RAS.png

** My hypothesis is that the gradients written to the nhdr file have already been adjusted for the measurement frame, and should have an identity measurement frame written to the nhdr file.

dcm2xml dump of unique gradient directions :

<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0\0\0</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.012201349250972271\-0.30893415212631226\-0.95100516080856323</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.030301757156848907\0.99335759878158569\0.11100643873214722</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.045702487230300903\-0.50612753629684448\0.86124688386917114</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.052103474736213684\0.76135081052780151\0.64624309539794922</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.058404784649610519\0.88587254285812378\-0.46023771166801453</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.068602532148361206\-0.72052657604217529\0.6900254487991333</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.095205090939998627\-0.97725224494934082\0.18951015174388885</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.095703192055225372\0.91233038902282715\0.39811325073242188</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.097409039735794067\-0.017401615157723427\-0.99509227275848389</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.12591651082038879\-0.55597281455993652\-0.82160770893096924</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.19661939144134521\0.51395070552825928\0.83498233556747437</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.20745235681533813\-0.21821640431880951\0.95359587669372559</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.20891833305358887\0.96118438243865967\-0.18021582067012787</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.21170790493488312\-0.89443331956863403\-0.39391469955444336</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.23130999505519867\0.085203677415847778\0.96914190053939819</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.23631173372268677\0.3815189003944397\-0.89364427328109741</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.24782006442546844\0.67725485563278198\-0.69275611639022827</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.25242796540260315\-0.84649378061294556\0.4687519371509552</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.26281514763832092\0.03650210052728653\-0.96415549516677856</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.26331707835197449\-0.73304754495620728\-0.62714064121246338</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.26432794332504272\-0.95900142192840576\-0.10221081227064133</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.31201356649398804\0.20160876214504242\0.92844033241271973</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.31593233346939087\0.36493733525276184\-0.87578964233398438</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.32800450921058655\-0.93841290473937988\-0.10860149562358856</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.3430233895778656\0.60464119911193848\-0.71884900331497192</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.34742775559425354\-0.69395536184310913\-0.63065034151077271</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.35140672326087952\-0.82261574268341064\0.44700857996940613</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.35742121934890747\0.35692119598388672\0.86305117607116699</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.36681774258613586\-0.12360598146915436\0.92204463481903076</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.38742718100547791\0.90016311407089233\-0.19901394844055176</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.39812362194061279\-0.83344942331314087\-0.38322269916534424</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.48302683234214783\-0.38982164859771729\-0.78404349088668823</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.49646157026290894\0.54926812648773193\0.67218339443206787</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.50013422966003418\-0.85015815496444702\0.16461126506328583</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.50084042549133301\0.78316324949264526\0.36852973699569702</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.5039406418800354\-0.52384233474731445\0.6867554783821106</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.51113784313201904\-0.074505530297756195\-0.85626339912414551</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.51803362369537354\0.69684517383575439\-0.49603217840194702</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.52565819025039673\-0.15371701121330261\0.83669263124465942</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.5375480055809021\0.83927488327026367\0.081607282161712646</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.54132980108261108\-0.37422060966491699\0.75294148921966553</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.58161717653274536\0.07790229469537735\0.80972385406494141</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.60163193941116333\0.66933554410934448\-0.43592315912246704</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.6055566668510437\0.78537344932556152\0.12841200828552246</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.61187523603439331\0.54336678981781006\0.57477062940597534</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.63188499212265015\0.65058749914169312\0.42125669121742249</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.63682979345321655\-0.73673450946807861\0.22731064260005951</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.64153283834457397\0.09620492160320282\-0.76103895902633667</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.66265147924423218\-0.29692307114601135\-0.68755346536636353</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.70096653699874878\0.30652907490730286\-0.64396107196807861</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.71078306436538696\-0.47175514698028564\0.52176100015640259</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.74076402187347412\0.65625673532485962\-0.14351239800453186</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.74783825874328613\-0.26261341571807861\-0.60973119735717773</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.74916738271713257\-0.5771518349647522\-0.32502922415733337</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.75385051965713501\-0.0016001053154468536\0.65704405307769775</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.76294434070587158\-0.64493745565414429\-0.044402576982975006</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.79843872785568237\-0.44962185621261597\0.4004194438457489</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.79965633153915405\-0.40952885150909424\-0.43913090229034424</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.81555986404418945\-0.55824095010757446\-0.15241117775440216</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.82435548305511475\0.19901338219642639\-0.52993565797805786</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.82806932926177979\0.50444221496582031\-0.24462047219276428</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.88485729694366455\0.12300796806812286\0.44932904839515686</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.88593631982803345\0.30671253800392151\0.34791421890258789</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.89860963821411133\0.1575016975402832\-0.40950441360473633</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.91114896535873413\-0.39332112669944763\0.12290661782026291</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.92109644412994385\0.38564038276672363\0.053505603224039078</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.93975090980529785\-0.23591278493404388\0.24741338193416595</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.94326275587081909\-0.016801116988062859\-0.33162206411361694</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">0.94589298963546753\0.2772272527217865\0.16861656308174133</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.98737597465515137\0.10160781443119049\-0.12150935083627701</element>
<element tag="0018,9089" vr="FD" vm="3" len="24" name="DiffusionGradientOrientation">-0.99453943967819214\-0.095403783023357391\-0.042301677167415619</element>

@hjmjohnson
Copy link
Author

NOTE:

The "measurement frame" is the RAS version of the inverse of the dicom ImageOrientationPatient field

dcm2xml ../301/DICOM/THP0001.MR.PHD_DTI_THP.301.102.20081016.153634.5483365599.dcm|grep Orientation 
<element tag="0020,0037" vr="DS" vm="6" len="102" name="ImageOrientationPatient">0.99996948242187\0.00759322009980\0.00183145038317\-0.0060658794827\0.90263313055038\-0.4303679764270</element>
import nrrd ## from pynrrd package

nrrd_hdr = nrrd.read_header(str(nrrd_dir / f"{file_prefix}.nhdr" ))
mf = nrrd_hdr["measurement frame"]

np.linalg.inv( mf )
Out[59]: 
array([[-0.99996999, -0.00606589,  0.00492101],
       [-0.00759323,  0.90263343, -0.43034422],
       [ 0.00183145,  0.43036769,  0.90265248]])

@neurolabusc
Copy link
Collaborator

@tashrifbillah is the developer and maintainer of the NRRD support. He describes the transforms here. He describes tests here and includes Python converters.

I tested the NIfTI code with FSL. I include compact Philips validation datasets for several generations of Philips software. The NITRC page contains many more large validation datasets - I also encourage users to read the dedicated document that is linked from that page that describes how to test the conversion of diffusion vectors.

@hjmjohnson
Copy link
Author

@neurolabusc Thank you for the information. The links are very useful. I'll reach out to @tashrifbillah.

Hans

@hjmjohnson
Copy link
Author

@neurolabusc @tashrifbillah Thank you for the python code! I'll review carefully and make queries if I run into any issues.

Thank you!

Hans

@neurolabusc
Copy link
Collaborator

@hjmjohnson it would be great to have an independent review of the dcm2niix NRRD conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants