Hi, I am a beginner in SimpleITK.
I used SimpleITK to load a nifti image and view its header information. The pixdim[0] header is changed from -1 to 0. I used ITKsnap, nifti-tool and nibabel to see the header information and they all show -1. Can anyone help me with this? I don’t know why this is happening.
This is the code I used to view the header in Simpleitk
brain_ncct_img = sitk.ReadImage(ncct_file)
brain_ncct_data = sitk.GetArrayFromImage(brain_ncct_img)
print("header using simpleitk")
for k in brain_ncct_img.GetMetaDataKeys():
v = brain_ncct_img.GetMetaData(k)
print("({0}) = = \"{1}\"".format(k,v))
I’m not sure I understand why pixdim[0] is important outside of I/O. Once you have read the image, it has an ITK transform that can take points to and from the physical space.
I have nifti data with header pixdim[0] “-1” and when I read it using simpleitk and plot it using matplotlib, the image is upside down. I am guessing it has to do something with pixdim[0] and I wanted to test theory but while reading simpleitk is making pixdim[0] “0” and if pixdim[0] is 0, i think we use qfac is 1.
It seems like ITK/SimpleITK might be re-doing the image orientation information. But, as Philip is asking, the orientation might work out to be the same. And if you’re using matplotlib to display an image, are you even using that orientation information?
I am actually using the array from this code sitk.GetArrayFromImage(brain_ncct_image) to create montage and sometimes the images in the montage is upside down but when I view it using ITK-snap it looks ok.
Accessing the image as a numpy array also ignores any orientation information. Perhaps you need to look at the orientation matrix for each image and decide if you need to flip the pixels.