-
Notifications
You must be signed in to change notification settings - Fork 45
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
Nifti to DICOM #56
Comments
It is possible to do some processing on NIfTI, and then save into dicom. But with those header information stored in NIfTI header, the result dicom will be missing a lot of information. This is because, during dicom to NIfTI conversion, most of the dicom header info are dropped. If you have the original dicom, you could replace the dicom image with processed NIfTI image. Of course you will need to take care of the NIfTI image reorient, flip and/or transpose before you put it into dicom. |
Is there code to obtain ImageOrientation and ImagePositionPatient from NIfTI header? Something similar to reverse of xform_mat function. |
@adityaapte
If the NIfTI file stores the correct dim_info, it is possible to reverse Position and Orientation into DICOM space. This info is in
|
Thanks. So we will need metadata to reverse the transforms that were applied while writing NIfTI. Any guidance on obtaining this metadata (like flp below) will be great. Here are some of the transformations I found in the code-base to go from DICOM to NIfTI coordinates.
In set_nii_hdr.m:
|
For example, the following produced dicom orientation and position from NIfTI for a non-oblique dataset.
|
It seems you do need Position and Orientation in DICOM? This is relatively easy for axial acquisition (hdr.dim_info=[1 2 3]), but for sagittal and coronal acquisition, it will be complicated, and you also need valid hdr.dim_info stored, and this is not always the case for some DICOM to NIfTI converters. If you use my dicm2nii.m, you won't bother for this, since a file, named dcmHeaders.mat, is always saved together with the NIfTI files, and you can get ALL dicom headers for each NIfTI. I am curious about the purpose of going back to DICOM. |
The purpose of going back to DICOM is to (1) archive analysis results (e.g. segmentation, deformation vector field, derived images etc) and (2) maintain compatibility with patient data that is already available in DICOM format. For example, we might have CT, RTDOSE, RTSTRUCT, PR etc modalities for a patient. We perform analysis using NIfTI format and obtain a resulting NIfTI file for deformation vector field. We would like to convert it to DICOM format so that all objects associated with the patient are in the same format. In me experience, using the nii file exported from dicm2nii, the coordinates match between the imported DICOM series and and nii file in 3DSlicer. This is true for axial, sag, cor or oblique scans. So it seems that the NIfTI file has the metadata to reproduce DICOM coordinates without hdr.dim_info. |
If you perform some processing to the images and like to save them into dicom format, the best way is to preserve the original dicom header, and modify some of them and then replace the images with processed images. The only confusion may happen when NIfTI converter reorient and/or flip axis for the DICOM image. Besides left/right storage (you can turn off the left-handed storage for the converter), there is a fixed pattern for dealing with each of TRA/SAG/COR acquisition. During dicm2nii conversion, only a TINY bit of the dicom info are save in nii. So without original dicom header, most information are lost. |
@adityaapte You can do your process on these nii files, and it will be much easier to store the processed images back into DICOM. There is no need to flip images or swap axis, and you can simply keep the original DICOM header, including ImageOrientaionPatient and ImagePositionPatien. Reorient is not necessory according to NIfTI standard. Converters tend to do it for better compatibility with some packages, like FSL. If you can process the nii without issue, this option should avoid all the confusions Let me know if you see any issues. |
Thanks for you work on this @xiangruili. I am looking to convert a nii to dicom. I was looking for a 'nii2dicm' function in this repo but don't see one. Is that function available? I was hopeful since in your comment above you mentioned nii2dcm ("I was thinking a way to make nii2dcm easier for you"). Right now we load into 3d slicer and export to dicom, but it would be really helpful to script this. Thanks :) |
@prlabu
|
Is it possible to convert a set of DICOM images into nifti, and do some processing, and the convert the derived nifti files back to DICOM with headers saved during the DICOM to nifti conversion using dicm2nii and provided tools?
Thanks in advance.
The text was updated successfully, but these errors were encountered: