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

How to fix dcm2nii transform #29

Closed
sunflowercyh opened this issue Apr 16, 2013 · 9 comments
Closed

How to fix dcm2nii transform #29

sunflowercyh opened this issue Apr 16, 2013 · 9 comments

Comments

@sunflowercyh
Copy link

The method >> ni = readFileNifti(yourniftiFile);ni = niftiSetQto(ni,ni.sto_xyz);writeFileNifti(ni); suggested by frakkopesto in #28 created a ni struct, in which there were many parameters( for image converted by dcm2nii, values of freq_dim, phase_dim and slice_dim is 0, while values for images converted by MRIConverter seems right-1,2,3 respectively, see pictures for more detail).
ni created for dcm2nii conversion
ricron

ni created for MRIConvert conversion
riconverter

But I am not clear what to do next, I tried to reset the value of freq_dim, phase_dim and slice_dim to 1,2,3 respectively(There are also something wrong with Qto matrix, but I'm not sure how to fix ) and saved the ni struct with names corresponding to original nii images. Then used mrInit again, but that make no difference and warnings listed below.

Warning: [niftiSet] Qto matrix defines an origin very far away from the isocenter.
Warning: [niftiSet] This implies that the Qto matrix could be bad. Please check qto_ijk.
Warning: [niftiSet] Origin to the image center is at [64.000,64.000,17.500] pix.

freq_dim not set correctly in NIFTI header.
phase_dim not set correctly in NIFTI header.
[niftiCheckQto] NIFTI header origin is at or outside the image volume.
[niftiCheckQto] Origin to the image center [64.000,64.000,17.500] pix.
??? Subscript indices must either be real positive integers or logicals.

How to solve this problem, and what to do next when the ni struct is created? Any suggestions? Thanks!

@aspanu
Copy link
Contributor

aspanu commented Apr 16, 2013

It looks like the header is still not set correctly - specifically the freq_dim and phase_dim. Just to confirm - you save down those changes that you made into the nifti file right? That is, once you have fixed the dims to be non-zero, you make another call to 'niftiWrite' is that correct?

@sunflowercyh
Copy link
Author

Thanks! Now mrnit works though there are still warnings like [niftiSet] This implies that the Qto matrix could be bad. Please check qto_ijk.BTW,how to change ato_ijk?

However, when open mrVista,the image is upside down,and cannot slide to view different slice as before (use old code) .

Screen shot of mrvista inplane window:
inplane

Information on matlab command window:

mrvista
mrVista version: 3
Matlab version: 7.11
Initializing Inplane view
Attaching menus
[niftiCheckQto] NIFTI header origin is at or outside the image volume.
[niftiCheckQto] Origin to the image center [64.000,64.000,17.500] pix.
Attaching popup menus
Attaching sliders
Could not find /media/D434B98834B96E5C/0417radibar/Inplane/userPrefs.mat
Done initializing Inplane view

nifti file information:
data: [4-D int16]
fname: 'scan2.nii'
ndim: 4
dim: [128 128 35 96]
pixdim: [1.5000 1.5000 2 2]
scl_slope: 1
scl_inter: 0
cal_min: 0
cal_max: 0
qform_code: 2
sform_code: 2
freq_dim: 1
phase_dim: 2
slice_dim: 3
slice_code: 0
slice_start: 0
slice_end: 0
slice_duration: 0
quatern_b: 0
quatern_c: 0.4548
quatern_d: 0.8906
qoffset_x: 96.8253
qoffset_y: 45.4340
qoffset_z: -89.1751
qfac: -1
qto_xyz: [4x4 double]
qto_ijk: [4x4 double]
sto_xyz: [4x4 double]
sto_ijk: [4x4 double]
toffset: 0
xyz_units: 'mm'
time_units: 'sec'
nifti_type: 1
intent_code: 0
intent_p1: 0
intent_p2: 0
intent_p3: 0
intent_name: ''
descrip: ''
aux_file: ''
num_ext: 0

@JWinawer
Copy link
Member

I don't know anything about the slice slider problem. But I do know about the upside-down issue. When the code was updated to use NIFTI's rather than Matlab matrices to store inplane images, we made a choice about how to display brains (that is, about the orientation). I believe the view in your attached image accurately reflects the orientation we specified in the code. So this view is not a bug in your NIFTI or the code. However, a couple of people have pointed out that they like the brains oriented the other way on the vertical axis. I'm not sure that one orientation or the other is objectively correct, since the brain is not actually in your screen. That said, on the next major upgrade, we will probably reverse the images vertically (compared to now) because people find that more natural. We do not want to change the code now because this will cause a mis-alignement between the inplane and functional data on sessions that are already initialized. The next major upgrade should happen in the next month or two.

@aspanu
Copy link
Contributor

aspanu commented Apr 17, 2013

As well, to build on top of what Jon said, the 'Left <---> Right' labels should still be accurate even if the image itself can be considered upside down. That is to say, the orientation is 'correct', albeit not completely standard.

In terms of your slice issues, I think that the problem that you are running into now is that your slice_start and slice_end dimensions are also zero. Those are used to calculate which slices to display (and thus, a mask can be chosen to be used in case certain frames need to be discarded) and need to be non-zero. You will probably need to use a similar fix to what you did with the dims.

It appears that the DICOM to NIFTI pipeline that you are using is potentially somewhat broken in that it doesn't populate a number of these fields that should be populated. I'd recommend you take a look at the wiki, and specifically http://white.stanford.edu/newlm/index.php/Anatomical-Processing#Data_Collected_from_SIEMENS_Scanners, looking at the 'Other Options' and trying some of those out. Especially in Linux, some of these methods should be higher fidelity in terms of producing a complete NIFTI.

Your problems should all go away if you change your method of going from DICOM to NIFTI.

@sunflowercyh
Copy link
Author

Jon and Adrian,thanks so much. dinifti and MRIConvert works and don't need fix.

@aspanu
Copy link
Contributor

aspanu commented Apr 18, 2013

Do you mind sharing with us what ended up solving the problem? We'd like to ensure that we capture all of the learning somewhere so that for the next time someone is having similar issues we'd be able to point them to that location and they can see how you ended up solving it.

Glad to hear that it is all working now, however!

@sunflowercyh
Copy link
Author

Sure, I am glad to write some details for newbies like me.

  1. If you convert Siemens dcm using dcm2nii, you need to fix the conversion
    you need to input >>ni = readFileNifti(yourniftiFile) in MATLAB to check whteher some parameters are correctly dimed, especially freq_dim, phase_dim,slice_dim,slice_start and slice_end.If values of these items are 0, you need to modify them, which you can refer to http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/dim_info.html offerd by rfdougherty in Fixing a bug found for niftis without proper freqdim and phasedim fields. #28. After you change these values, remeber to wirte these changes to your niftifiles with the command >>writeFileNifti(ni).
  2. A prefer way to solve this issue is to try other tools. I find dinifti and MRIConvert perform well.

Note: If you use a mean file as the anatomy inplane and you generate it with other software like SPM, instead of using vistasoft command-line. Make sure that you check and fix the resulting nifty file as described in method 1. Actually, most of my struggle comes from my neglect of errors in this file.

@aspanu
Copy link
Contributor

aspanu commented Apr 19, 2013

Thank you for your write-up. This will be very helpful for others encountering similar issues. I have updated the wiki with your comments here: http://white.stanford.edu/newlm/index.php/Anatomical-Processing#Data_Collected_from_SIEMENS_Scanners as well as referred back to this issue.

@arokem
Copy link
Member

arokem commented Apr 19, 2013

Also now immortalized here:

https://github.com/vistalab/vistasoft/wiki/Siemens-dicoms-converted-with-dcm2nii

On Fri, Apr 19, 2013 at 9:35 AM, Adrian Spanu notifications@github.comwrote:

Thank you for your write-up. This will be very helpful for others
encountering similar issues. I have updated the wiki with your comments
here:
http://white.stanford.edu/newlm/index.php/Anatomical-Processing#Data_Collected_from_SIEMENS_Scannersas well as referred back to this issue.


Reply to this email directly or view it on GitHubhttps://github.com//issues/29#issuecomment-16663618
.

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

4 participants