【问题标题】:How to perform thresholding?如何进行阈值处理?
【发布时间】:2018-06-28 22:54:03
【问题描述】:

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

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] 缓冲区域: 尺寸: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

向量长度:4 像素容器: ImportImageContainer (0x24ba950) RTTI 类型信息:itk::ImportImageContainer 参考数:1 修改时间:1285 调试:关闭 对象名称: 观察员: 没有任何 指针:0x30bb390 容器管理内存:true 尺寸:372100 容量:372100

【问题讨论】:

    标签: python image-processing simpleitk image-thresholding


    【解决方案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 图像?以及如何处理多通道图像的“阈值化”?

    【讨论】:

    • 实际上我使用itksnap将一个nii图像保存到png中。如何对其进行阈值处理?我用 print 编辑了问题
    • 你能帮我从 305*305*39 nii 图像中提取切片吗
    • print(img.GetNumberOfComponentsPerPixel()) 返回 4
    • 听起来您的错误是将医学图像保存为 png。 “帮我提取?”那是一个不同的问题。 print 输出格式不佳的编辑问题表明组件数为 4。
    • 组件数为4
    猜你喜欢
    • 1970-01-01
    • 2021-12-23
    • 2015-10-19
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    相关资源
    最近更新 更多