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