应用阈值设置时出现错误:
import SimpleITK as sitk
img = sitk.ReadImage("Sub1.png")
img=img>20
错误是:
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
我应用了img = sitk.Image(img.GetSize(), sitk.sitkUInt8)
,但是图像变黑了。
Python中是否有诸如double(img)
或im2bw
之类的选项?会正常工作吗?
print(img)提供以下内容
VectorImage(0x2f57af0)RTTI类型信息:itk :: VectorImage参考计数:1修改时间:1289调试:关闭对象名称:观察者: 无源:(无)源输出名称:(无)发布数据:关闭数据发布:False全局发布数据:关闭PipelineMTime:1278 UpdateMTime:1288 RealTimeStamp:0秒LargestPossibleRegion: 尺寸:2 索引:[0,0] 大小:[305、305] BufferedRegion: 尺寸:2 索引:[0,0] 大小:[305、305] RequestedRegion: 尺寸:2 索引:[0,0] 大小:[305,305]间距:[1,1]起点:[0,0]方向:1 0 0 1
IndexToPointMatrix:1 0 0 1
PointToIndexMatrix:1 0 0 1
反方向:1 0 0 1
VectorLength:4 PixelContainer: ImportImageContainer(0x24ba950) RTTI类型信息:itk :: ImportImageContainer 参考计数:1 修改时间:1285 调试:关闭 对象名称: 观察员: 没有 指针:0x30bb390 容器管理内存:true 尺寸:372100 容量:372100
答案 0 :(得分:1)
您的异常显示为:
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
尝试运行:
import SimpleITK as sitk
img = sitk.ReadImage("Sub1.png")
print img
这意味着您输入的图像不是标量图像,而是具有多个分量的图像。 “>”或sitk.GraterThan
不支持矢量图像。它仅支持标量图像。
问题是:您的图像应该是RGB图像吗?您想如何处理“阈值”多通道图像?