Skip to content
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 files flipped left-right / coordinate system #17

Open
tpenzkofer opened this issue Jul 24, 2020 · 5 comments
Open

NIFTI files flipped left-right / coordinate system #17

tpenzkofer opened this issue Jul 24, 2020 · 5 comments

Comments

@tpenzkofer
Copy link

Hi,

I have two - maybe related issues,

  1. I have some Nifti files (derived from DICOM using dcm2niix) which are flipped left-right in cornerstone when loaded through cornerstone-nifti-image-loader, any ideas?

  2. when calculating the patient space positions using "imagePointToPatientPoint" from cornerstoneTools using the imagePlane metaData information from cornerstone-nifti-loader the derived x/y coordinates are from the opposite corner of the image and the z coordinate is completely off (imagePointToPatientPoint does not take into account imageOrientationPatient, maybe that's the problem), as compared to Slicer RAS fiducial coordinates

Any ideas?

@tpenzkofer
Copy link
Author

Specifically: The Patientposition matrix within cornerstone-nifti-image-loader ist different from slicers Image Origin (that shouldn't happen, imho)

cornerstone:
coordinates1

slicer:
Screen Shot 2020-07-25 at 12 30 45

@tpenzkofer
Copy link
Author

ok, some more digging, the matrices / images are apparently flipped in these two function calls in Volume.js:

    this[convertToNeurologicalView]();
    this[convertRAStoLPS]();

Omitting them restores the correct imageOrientation matrix and ijk->patient space calculations are okay again BUT images are flipped bottom-up and left-right in cornerstone...

@tpenzkofer
Copy link
Author

tpenzkofer commented Jul 26, 2020

even more digging, looks like all three functions call

this[ensureVoxelStorageInXYZ]();
this[convertToNeurologicalView]();
this[convertRAStoLPS]();

are distorting the coordinate calculations when displaying it in cornerstone / doing ijk->patientspace calculations (I presume the when flipping the rotation matrix signs the origin coordinates need to be recalculated as well, especially in case of off-axis imaging), any thoughts on that?

@ramonemiliani93
Copy link

Hi @tpenzkofer! Did you manage to solve this? I am facing the same problem with the loader, Nifti files appear to be flipped.

@ramonemiliani93
Copy link

For anyone that runs into the same issue, it seems OHIF changed from Neurological to Radiological convention hence the image looks flipped on latest versions. The issue can be easily fixed by changing line 181 of the Volume.js file, instead of

      // if 'X-', we need to flip x axis so patient's right is
      // shown on the right
      if (senses[0] === '-') {
        matrix[0][0] *= -1;
        matrix[0][1] *= -1;
        matrix[0][2] *= -1;
        matrix[0][3] *= -1;
        steps[0] = -1;
      }
      // if 'Y+' we need to flip y axis so patient's anterior is shown on the
      // top
      if (senses[1] === '+') {
        matrix[1][0] *= -1;
        matrix[1][1] *= -1;
        matrix[1][2] *= -1;
        matrix[1][3] *= -1;
        steps[1] = -1;
      }
      // if 'Z+' we need to flip z axis so patient's head is shown on the top
      if (senses[2] === '+') {
        matrix[2][0] *= -1;
        matrix[2][1] *= -1;
        matrix[2][2] *= -1;
        matrix[2][3] *= -1;
        steps[2] = -1;
      }
    }

you can change the convention to the Radiological view by switching the line to

      // if 'X+', we need to flip x axis so patient's right is
      // shown on the left
      if (senses[0] === '+') {
        matrix[0][0] *= -1;
        matrix[0][1] *= -1;
        matrix[0][2] *= -1;
        matrix[0][3] *= -1;
        steps[0] = -1;
      }
      // if 'Y+' we need to flip y axis so patient's anterior is shown on the
      // top
      if (senses[1] === '+') {
        matrix[1][0] *= -1;
        matrix[1][1] *= -1;
        matrix[1][2] *= -1;
        matrix[1][3] *= -1;
        steps[1] = -1;
      }
      // if 'Z+' we need to flip z axis so patient's head is shown on the top
      if (senses[2] === '+') {
        matrix[2][0] *= -1;
        matrix[2][1] *= -1;
        matrix[2][2] *= -1;
        matrix[2][3] *= -1;
        steps[2] = -1;
      }
    }

Ideally the method should be renamed from convertToNeurologicalView to convertToRadiologicalView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants