sitkUtils.PullVolumeFromSlicer does not create sitk::Image in Slicer 5.1

Using sitkUtils.PullVolumeFromSlicer

                from lungmask import mask
                import SimpleITK as sitk
                import sitkUtils

                self.showStatusMessage(' Creating lungs with AI ...')
                inputVolumeSitk = sitkUtils.PullVolumeFromSlicer(self.inputVolume)
                print(inputVolumeSitk)

to create an input volume for “lungmask” AI produces in Slicer 5.0.3 Stable correctly:

Image (000001DF82D79C40)
  RTTI typeinfo:   class itk::Image<int,3>
  Reference Count: 1
  Modified Time: 1021
  Debug: Off
  Object Name: 
  Observers: 
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 1010
  UpdateMTime: 1020
  RealTimeStamp: 0 seconds 
  LargestPossibleRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 139]
  BufferedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 139]
  RequestedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 139]
  Spacing: [0.761719, 0.761719, 2.5]
  Origin: [-195, -171.7, -347.75]
  Direction: 
1 0 0
0 1 0
0 0 1

  IndexToPointMatrix: 
0.761719 0 0
0 0.761719 0
0 0 2.5

  PointToIndexMatrix: 
1.31282 0 0
0 1.31282 0
0 0 0.4

  Inverse Direction: 
1 0 0
0 1 0
0 0 1

  PixelContainer: 
    ImportImageContainer (000001DF835BDC50)
      RTTI typeinfo:   class itk::ImportImageContainer<unsigned __int64,int>
      Reference Count: 1
      Modified Time: 1018
      Debug: Off
      Object Name: 
      Observers: 
        none
      Pointer: 000001DF904FB040
      Container manages memory: true
      Size: 36438016
      Capacity: 36438016

In Slicer Slicer 5.1.0-2022-10-11 (Windows 11) the same call produces


Image (0000025AE2411E50)
  RTTI typeinfo:   class slicer_itk::Image<int,3>
  Reference Count: 1
  Modified Time: 6368
  Debug: Off
  Object Name: 
  Observers: 
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 6349
  UpdateMTime: 6364
  RealTimeStamp: 0 seconds 
  LargestPossibleRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 139]
  BufferedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 139]
  RequestedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 139]
  Spacing: [0.761719, 0.761719, 2.5]
  Origin: [-195, -171.7, -347.75]
  Direction: 
1 0 0
0 1 0
0 0 1

  IndexToPointMatrix: 
0.761719 0 0
0 0.761719 0
0 0 2.5

  PointToIndexMatrix: 
1.31282 0 0
0 1.31282 0
0 0 0.4

  Inverse Direction: 
1 0 0
0 1 0
0 0 1

  PixelContainer: 
    ImportImageContainer (0000025AE1A17D20)
      RTTI typeinfo:   class slicer_itk::ImportImageContainer<unsigned __int64,int>
      Reference Count: 1
      Modified Time: 6361
      Debug: Off
      Object Name: 
      Observers: 
        none
      Pointer: 0000025AEEC28040
      Container manages memory: true
      Size: 36438016
      Capacity: 36438016

and leads to this exception:

Failed to compute results: in method 'GetByteArrayFromImage', argument needs to be of type 'sitk::Image *'
Traceback (most recent call last):
  File "C:/Users/Rudolf/Documents/MySlicerExtensions/SlicerLungCTAnalyzer/LungCTSegmenter/LungCTSegmenter.py", line 519, in onApplyButton
    self.logic.applySegmentation()
  File "C:/Users/Rudolf/Documents/MySlicerExtensions/SlicerLungCTAnalyzer/LungCTSegmenter/LungCTSegmenter.py", line 1510, in applySegmentation
    segmentation_np = mask.apply(inputVolumeSitk)  # default model is U-net(R231), output is numpy
  File "C:\Users\Rudolf\AppData\Local\NA-MIC\Slicer 5.1.0-2022-10-11\lib\Python\Lib\site-packages\lungmask\mask.py", line 31, in apply
    inimg_raw = sitk.GetArrayFromImage(image)
  File "C:\Users\Rudolf\AppData\Local\NA-MIC\Slicer 5.1.0-2022-10-11\lib\Python\Lib\site-packages\SimpleITK\extra.py", line 269, in GetArrayFromImage
    array_view = GetArrayViewFromImage(image)
  File "C:\Users\Rudolf\AppData\Local\NA-MIC\Slicer 5.1.0-2022-10-11\lib\Python\Lib\site-packages\SimpleITK\extra.py", line 255, in GetArrayViewFromImage
    image_memory_view = _GetMemoryViewFromImage(image)
TypeError: in method 'GetByteArrayFromImage', argument needs to be of type 'sitk::Image *'

Thanks for reporting. @jcfr has been working on upgrades to the itk/sitk implementation and this should help him debug.

Thanks for the report :pray:

I will look into the details and report back.

This problem is likely captured by the now failing test py_nomainwindow_test_sitkUtils

Links:

2 Likes

I ran into this as well when updating to use latest Slicer version in my custom app. I added a GitHub issue for it in addition to this post.

2 Likes

Hi,

Just for planning:
… will this be solved before 5.1 becomes the new stable 5.2?

Thank you

We will not release the new stable version (5.2) until this problem is fixed.

Updates:

  • The regression is expected to be fixed by pull request #6606 that just got integrated.
  • Preview release packages should be available at https://download.slicer.org tomorrow around 11am ET

cc: @blowekamp

3 Likes

Thank you @jcfr, this seems to be fixed in 5.1.0-2022-10-21 r31237 / c1715b5 .

1 Like