How 3DSlicer compute image origin and IJK to RAS direction matrix.

Hello everybody, this is my first topic and I have some trouble reasoning with 3Dslicer DICOM parameters extraction. I start from the beginnig. Due to research activity, my aim is to write down a python code (without slicer package) to convert a MRI DICOM series to a Nifti file and apply on it a segmentation mask through the affine matrix. I obtained my conversion and compared it with the one produced by 3DSlicer on the same DICOM series through the export to file functionality. I obtained pretty similar results, but the orientation is different. I try to explain myself better. The IJK to RAS direction matrices have both all zeros and ones on the diagonal for both the results but with different signs for the first two dimensions, while the origin has the same modules but different signs (on the first two dimensions). I don’t understand how 3DSlicer computes my same direction matrix and origin but with different signs. Moreover the segmentation is overlapping perfectly on 3DSlicer output, but not on mine. I hope you can understand what I mean. Thank a lot!

I would not recommend to do this, because while it is extremely complex to implement this correctly for a wide range of DICOM objects, it is considered to be a solved problem. You can use Slicer for this using with or without GUI (using Python scripting), but if you don’t want to do that then another very robust and comprehensive 3D image reconstruction software is dcm2niix. There are many other software that works for well for some of the most common inaging protocols (such as ITK and VTK DICOM readers), but they cannot produce correct results for tilted-gantry acquisitions, non-uniform slice spacing, 4D images, etc.