pyushkevich/itksnap

Failed to load image "Image has an invalid orientation (code IRI) "

dhinkris opened this issue · 3 comments

I am trying to open a .nii.gz image. For a specific set of 'affine' matrix, ITK snap throws the Image has an invalid orientation (code IRI) error. The header seems correct (Right-to-Left, Anterior-to-Posterior, Inferior-to-Superior) in which case it is an RAI orientation but I see the error as above. It seems like ITK-Snap internally computes the orientation based on the affine matrix which seems to be causing this issue. This works fine FSLEyes/3D Slicer. Your help is much appreciated.

The error can be replicated with the below snippet.

import nibabel as nib
import numpy as np

data=np.random.random((256,256,56))
affine=[[-0.656692, -0.676962, 0.332383, -0.000000],
        [0.360389, -0.668844, -0.650205, -0.000000],
        [0.662477, -0.307197, 0.683194, 0.000000],
        [0.000000, 0.000000, 0.000000, 1.000000]
nifti_img=nib.Nifti1Image(data, affine=affine
nib.save(nifti_img, "orientation_test.nii.gz")

Below is the header information of that specific nifti file
sizeof_hdr 348
data_type FLOAT64
dim0 3
dim1 256
dim2 256
dim3 56
dim4 1
dim5 1
dim6 1
dim7 1
vox_units Unknown
time_units Unknown
datatype 64
nbyper 8
bitpix 64
pixdim0 1.000000
pixdim1 1.000000
pixdim2 1.000000
pixdim3 1.000000
pixdim4 1.000000
pixdim5 1.000000
pixdim6 1.000000
pixdim7 1.000000
vox_offset 352
cal_max 0.000000
cal_min 0.000000
scl_slope 1.000000
scl_inter 0.000000
phase_dim 0
freq_dim 0
slice_dim 0
slice_name Unknown
slice_code 0
slice_start 0
slice_end 0
slice_duration 0.000000
toffset 0.000000
intent Unknown
intent_code 0
intent_name
intent_p1 0.000000
intent_p2 0.000000
intent_p3 0.000000
qform_name Unknown
qform_code 0
qto_xyz:1 -0.656692 -0.676962 0.332383 -0.000000
qto_xyz:2 0.360389 -0.668844 -0.650205 -0.000000
qto_xyz:3 0.662477 -0.307197 0.683194 0.000000
qto_xyz:4 0.000000 0.000000 0.000000 1.000000
qform_xorient Right-to-Left
qform_yorient Anterior-to-Posterior
qform_zorient Inferior-to-Superior
sform_name Unknown
sform_code 2
sto_xyz:1 -0.656692 -0.676962 0.332383 -0.000000
sto_xyz:2 0.360389 -0.668844 -0.650205 -0.000000
sto_xyz:3 0.662477 -0.307197 0.683194 0.000000
sto_xyz:4 0.000000 0.000000 0.000000 1.000000
sform_xorient Right-to-Left
sform_yorient Anterior-to-Posterior
sform_zorient Inferior-to-Superior
file_type NIFTI-1+
file_code 1
descrip
aux_file

Any suggestions would be really helpful.

Thank you.
Regards,
Dhinesh

You're getting this error because ITK-SNAP tries to figure out which axis maps to coronal, axial and sagital views. (Something Slicer does not, it has red/green/yellow views with no anatomical meaning in particular). To do this, ITK-SNAP assumes that the matrix is the transform to LPI and uses that to figure out the mapping. In your case, the maximum (in absolute value) of columns 1 and 3 are both in row 3, so no mapping is possible.

A workaround is to reset the transform to identity, however this means that if you open another image, the shared cursor feature won't work.

What kind of image are you trying to open? I suspect it's not MRI/scanner for which L/R, P/A, I/S makes sense. I've had the case for freehand ultrasound volumes for which the transform is arbitrary and no axis can be meaningfully labelled as L/R, P/A or I/S. It would be helpful that in case no mapping is possible, ITK-SNAP assigns an arbitrary one and still opens the image.

@fx-carton Thanks for clarifying this. Now I clearly understand the problem.

I am working on fetal MRI scans. The modality is T2 SSFSE and we perform three acquisitions close which closely resemble axial, sagittal, and coronal. And then perform Slice to Volume reconstruction(overlay based on registration). If I reset them to identify affine the images will open, but the shared cursor won't be in place as you mentioned which means the position of the acquisitions is far away from each other relative to the origin. This gets complicated during the reconstruction step as it is heavily based on registration.
Yes, it would be helpful if ITK-SNAP assigns an arbitration orientation and opens up the images.

My requirement is to transform all three acquisitions to a valid orientation but still retain their relative positions. Let me know if you understood the problem and have any workaround for this.

Thanks again for taking the time to explain this. Very helpful.

Regards,
Dhinesh

I am also facing the same issue. The data is from real clinical shoulder MRI case. Any ideas?

Here is the direction cosine matrix:

[[-0.71844119  0.06575722 -0.69247257]
 [ 0.67544218  0.30380508 -0.67192283]
 [ 0.16619304 -0.95046224 -0.26268128]]

Image Orientation (Patient) [dicom tag (0020,0037)] in the original dicom is
-0.718441\0.675442\0.166193\0.0657572\0.303805\-0.950462

It loads fine in slicer3D and dicom viewers.