Reputation: 5
When I apply thresholding I'm getting an error:
import SimpleITK as sitk
img = sitk.ReadImage("Sub1.png")
img=img>20
The error is:
RuntimeError Traceback (most recent call last)
<ipython-input-48-a1d4494dca15> in <module>()
1 #img = sitk.Image(img.GetSize(), sitk.sitkUInt8)
----> 2 img=img>20
~/sitkpy/lib/python3.5/site-packages/SimpleITK/SimpleITK.py in __gt__(self, other)
4424 return Greater( self, other )
4425 try:
-> 4426 return Greater( self, float(other) )
4427 except (ValueError, TypeError):
4428 return NotImplemented
~/sitkpy/lib/python3.5/site-packages/SimpleITK/SimpleITK.py in Greater(*args)
34345
34346 """
> 34347 return _SimpleITK.Greater(*args)
34348 class GridImageSource(ImageFilter_0):
34349 """
RuntimeError: Exception thrown in SimpleITK Greater: /tmp/SimpleITK/Code/Common/include/sitkMemberFunctionFactory.hxx:209:
sitk::ERROR: Pixel type: vector of 8-bit unsigned integer is not supported in 2D byN3itk6simple18GreaterImageFilterE
I applied img = sitk.Image(img.GetSize(), sitk.sitkUInt8)
but I'm getting a black image.
Is there any option like double(img)
or im2bw
in Python? Will normalize work?
print(img) gives the following
VectorImage (0x2f57af0) RTTI typeinfo: itk::VectorImage Reference Count: 1 Modified Time: 1289 Debug: Off Object Name: Observers: none Source: (none) Source output name: (none) Release Data: Off Data Released: False Global Release Data: Off PipelineMTime: 1278 UpdateMTime: 1288 RealTimeStamp: 0 seconds LargestPossibleRegion: Dimension: 2 Index: [0, 0] Size: [305, 305] BufferedRegion: Dimension: 2 Index: [0, 0] Size: [305, 305] RequestedRegion: Dimension: 2 Index: [0, 0] Size: [305, 305] Spacing: [1, 1] Origin: [0, 0] Direction: 1 0 0 1
IndexToPointMatrix: 1 0 0 1
PointToIndexMatrix: 1 0 0 1
Inverse Direction: 1 0 0 1
VectorLength: 4 PixelContainer: ImportImageContainer (0x24ba950) RTTI typeinfo: itk::ImportImageContainer Reference Count: 1 Modified Time: 1285 Debug: Off Object Name: Observers: none Pointer: 0x30bb390 Container manages memory: true Size: 372100 Capacity: 372100
Upvotes: 0
Views: 484
Reputation: 1431
Your exception reads:
RuntimeError: Exception thrown in SimpleITK Greater: /tmp/SimpleITK/Code/Common/include/sitkMemberFunctionFactory.hxx:209:
sitk::ERROR: Pixel type: vector of 8-bit unsigned integer is not supported in 2D byN3itk6simple18GreaterImageFilterE
Try running:
import SimpleITK as sitk
img = sitk.ReadImage("Sub1.png")
print img
This means that your input image is NOT a scalar image it is an image with multiple components. The ">" or sitk.GraterThan
does not support vector images. It only support scalar images.
The question is: is your image suppose to be a RGB image? And how do you want to deal with "thresholding" the multi-channel image?
Upvotes: 2