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

**URL:** <https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669>\
**Category:** Development\
**Created:** [October 13, 2022, 8:17am UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669 "2022-10-13T08:17:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 13, 2022, 8:17am UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/1 "2022-10-13T08:17:56Z")

</div>

Using sitkUtils.PullVolumeFromSlicer

```auto
                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:

```auto
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

```auto

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:

```auto
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 *'

```

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 13, 2022, 2:16pm UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/2 "2022-10-13T14:16:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [October 13, 2022, 9:43pm UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/3 "2022-10-13T21:43:12Z")

</div>

Thanks for the report 🙏

I will look into the details and report back.

This problem is likely captured by the now failing test `py_nomainwindow_test_sitkUtils`

Links:

- CDash / SlicerPreview / Linux: [https://slicer.cdash.org/test/23216258](https://slicer.cdash.org/test/23216258)
- CDash / SlicerPreview / Windows: [https://slicer.cdash.org/test/23218352](https://slicer.cdash.org/test/23218352)

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [October 18, 2022, 9:58pm UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/4 "2022-10-18T21:58:55Z")

</div>

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.

> <https://github.com/Slicer/Slicer/issues/6598>
>
> \## Summary
> 
> SimpleITK usage in Slicer has had problems since the merging of 0d…1ed30a34f96ad5c5f367626347bf5b3a4f1e95. This was also reported at https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669
> 
> This issue appears to be captured by Slicer failed test https://slicer.cdash.org/test/23247998
> 
> \## Steps to reproduce
> 
> \`\`\`
> Python 3.9.10 (main, Oct 16 2022, 23:27:17) \[MSC v.1930 64 bit (AMD64)\] on win32
> \>\>\> import SimpleITK as sitk
> \>\>\> sitk.ReadImage(r"C:\\Users\\butlej30383\\Downloads\\MRHead.nrrd")
> \<SimpleITK.SimpleITK.Image; proxy of \<Swig Object of type 'slicer\_itk::simple::Image \*' at 0x0000017A7A8B8E10\> \>
> \>\>\> image = sitk.ReadImage(r"C:\\Users\\butlej30383\\Downloads\\MRHead.nrrd")
> \>\>\> image
> \<SimpleITK.SimpleITK.Image; proxy of \<Swig Object of type 'slicer\_itk::simple::Image \*' at 0x0000017A7A8B8F00\> \>
> \>\>\> image\_array = sitk.GetArrayFromImage(image)
> Traceback (most recent call last):
> File "\<console\>", line 1, in \<module\>
> File "C:\\Users\\butlej30383\\AppData\\Local\\NA-MIC\\Slicer 5.1.0-2022-10-15\\lib\\Python\\Lib\\site-packages\\SimpleITK\\extra.py", line 269, in GetArrayFromImage
> array\_view = GetArrayViewFromImage(image)
> File "C:\\Users\\butlej30383\\AppData\\Local\\NA-MIC\\Slicer 5.1.0-2022-10-15\\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 \*'
> \>\>\> 
> \`\`\`
> 
> \## Expected behavior
> 
> SimpleITK methods such as \`GetArrayFromImage\` should not return a traceback.
> 
> \## Environment
> \- Slicer version: Slicer-5.1.0-2022-10-15
> \- Operating system: Windows

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 19, 2022, 1:51pm UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/5 "2022-10-19T13:51:20Z")

</div>

Hi,

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

Thank you

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 19, 2022, 5:01pm UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/6 "2022-10-19T17:01:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [October 20, 2022, 11:49pm UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/7 "2022-10-20T23:49:51Z")

</div>

Updates:

- The regression is expected to be fixed by pull request [#6606](https://github.com/Slicer/Slicer/pull/6606) that just got integrated.
- `Preview` release packages should be available at [https://download.slicer.org](https://download.slicer.org) tomorrow around 11am ET

cc: @blowekamp

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 22, 2022, 3:12pm UTC](https://discourse.slicer.org/t/sitkutils-pullvolumefromslicer-does-not-create-sitk-image-in-slicer-5-1/25669/8 "2022-10-22T15:12:16Z")

</div>

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