Closed smcdouga closed 1 month ago
The issue is described in the documentation. The rationale for using nii_flipY by default is that the origin of DICOM is at the top of the screen, but for NIfTI it is the bottom: By convention, DICOM images are saved to disk in the order we read English: with the first line at the top of the screen and subsequent lines descending. In contrast, the default behavior of NIfTI if for the first line to be at the bottom of the screen and subsequent lines ascending, the way we draw the Y-coordinate of a Cartesian grid
.
This is the same as for Vulkan vs OpenGL:
This flipping is done in the s-form and does not influence the voxel data. It is lossless for any tool that properly uses the sform. The flip does aid simple tools that ignore this transform. Data flipping does take a tiny bit of time, so disabling nii_flipY does make image conversion a tiny bit faster (I/O is the main bottleneck). The initial releases of dcm2niix did not use nii_flipY, with the intention of being as close to the source DICOM as possible. My selfish rationale for implementing nii_flipY was to make the results identical to @xiangruili's excellent dicm2nii. The consistency between tools aids regression testing. DICOM has a lot of edge cases, and each manufacturer has their own interpretation, so the conversion developers work cooperatively.
Hi All,
Just want to take the time to say thank you for all the work that has been done on this project. I work at a neuroimaging lab and we use dcm2niix to handle the conversion from dicom to nifti. I am currently developing a tool to programmatically handle the cataloguing and conversion from dicom to nifti because we are encountering a lot of scenarios that require special considerations. To test it I am using dcm2niix as a highly credible benchmark. I had a couple questions about how the quaternion offsets and the S-Form parameters are set when converting a dicom volume to a nifti file.
The data I used was found from a neurolabusc repo: https://github.com/neurolabusc/dcm_qa_mprage; specifically the 2_t1_mp2rage_sag_p3_32 series.
Using the Image Orientation Patient and Image Position Patient of the first slice and following the method described in this paper (https://www.sciencedirect.com/science/article/pii/S0165027016300073?via%3Dihub) I get the following affine :
However, dcm2niix creates this affine:
Specifically the quaternion offsets
[-84.20596 145.42374 -133.45984]
are different and the first index of the z parameter s-form0.79936
is flipped.Why is this transformation being done and does it matter if the qform and sform are different in the nifti file? I have reviewed the source code and see that the function nii_flipY is doing the transforming, but I am not sure why it is being applied to the source image.