如何执行阈值?

How to perform thresholding?

当我应用阈值时出现错误:

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 调试:关闭 对象​​名称:观察者: none 来源:(none) 来源输出名称:(none) 发布数据:关闭 发布数据:假 全球发布数据:关闭 PipelineMTime:1278 UpdateMTime:1288 RealTimeStamp:0 秒 LargestPossibleRegion: 尺寸:2 索引:[0, 0] 大小:[305, 305] 缓冲区域: 尺寸:2 索引:[0, 0] 尺寸:[305, 305] 请求地区: 尺寸: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: 导入图像容器 (0x24ba950) RTTI 类型信息:itk::ImportImageContainer 参考计数:1 修改时间:1285 调试:关闭 对象名称: 观察员: none 指针:0x30bb390 容器管理内存:true 尺码:372100 容量:372100

您的例外情况如下: 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 图像?你想如何处理"thresholding"多通道图像?