Skip to content

INVALID Orientation in DICOMOrientImageFilter #1375

Closed

Description

@wwaleww

Hi,

I was used to set all my DICOM images to the 'LPS' orientation before processing them, using the following few lines of code:

orient = sitk.DICOMOrientImageFilter()
orient.SetDesiredCoordinateOrientation("LPS")
image = orient.Execute( image )

On one image series I get the following error:
"Exception thrown in SimpleITK DICOMOrientImageFilter_Execute: /Users/runner/work/1/sitk-build/ITK-prefix/include/ITK-5.2/itkPermuteAxesImageFilter.hxx:100 Order indices must not repeat"

When I print the orientation from coordinates, using orient.GetOrientationFromDirectionCosines (image.GetDirection()), I get INVALID.

The image direction is the following:
(0.5986634407395047, 0.22716302314740483, -0.768113953548866, 0.5627936241740271, 0.563067040943212, 0.6051601804419384, 0.5699696670095713, -0.794576911518317, 0.20924175102261847)

Would you have an idea of why would this direction be invalid?

Thanks in advance!

Activity

  1. blowekamp commented on Apr 13, 2021

    @blowekamp
    Member

    Please add: orient.DebugOn() to report additional output for what is occurring inside the ITK filter.

  2. wwaleww commented on Apr 13, 2021

    @wwaleww
    Author

    I added the debug, and using the following code:

    orient = sitk.DICOMOrientImageFilter()
    orient.DebugOn()
    print(image.GetDirection())
    print(orient.GetOrientationFromDirectionCosines(image.GetDirection()))
    orient.SetDesiredCoordinateOrientation("LPS")
    image = orient.Execute( image )
    

    I get the following output:

    (0.768113953548866, 0.5986634407395047, -0.22716302314740483, -0.6051601804419384, 0.5627936241740271, -0.563067040943212, -0.20924175102261847, 0.5699696670095713, 0.794576911518317)
    INVALID
    
    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-31-69e2af1b72a8> in <module>
          5 print(orient.GetOrientationFromDirectionCosines(image.GetDirection()))
          6 orient.SetDesiredCoordinateOrientation("LPS")
    ----> 7 image = orient.Execute( image )
          8 
    
    ~/opt/anaconda3/envs/working_env/lib/python3.8/site-packages/SimpleITK/SimpleITK.py in Execute(self, image1)
      20086 
      20087         """
    > 20088         return _SimpleITK.DICOMOrientImageFilter_Execute(self, image1)
      20089 
      20090 # Register DICOMOrientImageFilter in _SimpleITK:
    
    RuntimeError: Exception thrown in SimpleITK DICOMOrientImageFilter_Execute: /Users/runner/work/1/sitk-build/ITK-prefix/include/ITK-5.2/itkPermuteAxesImageFilter.hxx:100:
    Order indices must not repeat
    

    I hope this gives you more clues on what's the problem, and thanks again!

  3. blowekamp commented on Apr 22, 2021

    @blowekamp
    Member

    I have looked into this issue further. The matrix is orthonormal and has a determinate of 1 so it is valid but it is rather interesting. The first column is: [ 0.59866344, 0.56279362, 0.56996967] which is really in the middle of all three axis.

    The DICOMOrientImageFilter only permutes, and flips the axises. It does not do the arbitrary rotation to resample the image so it is exactly in LPS orientation. It is designed for the simple case of just changing the order of the axises. So for this particular direction the re orientation can not achieve results that are close to the desired LPS orientation.

    With that said, the numeric computation of the "closest" orientation can be improved so that it is robust to cases similar to this one.

  4. blowekamp commented on May 28, 2021

    @blowekamp
    Member

    Need to verify 2.1rc1 contains this fix.

  5. added this to the v2.1 milestone on May 28, 2021
  6. blowekamp commented on Aug 26, 2021

    @blowekamp
    Member

    This has been fixed in v2.1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions