Python 3.x 如何可视化标签图像

Python 3.x 如何可视化标签图像,python-3.x,image-processing,simpleitk,Python 3.x,Image Processing,Simpleitk,我想分割一个图像。我使用了简单的阈值方法。为此,我读取图像并将其转换为数组,然后转换img import SimpleITK as sitk import numpy as np header = sitk.ReadImage("Sub1.png") img = sitk.GetArrayFromImage(header) a=img img = ((img > 20) * 255).astype(np.uint8) # To visualize the labels image in R

我想分割一个图像。我使用了简单的阈值方法。为此,我读取图像并将其转换为数组,然后转换img

import SimpleITK as sitk
import numpy as np
header = sitk.ReadImage("Sub1.png")
img = sitk.GetArrayFromImage(header)
a=img
img = ((img > 20) * 255).astype(np.uint8)
# To visualize the labels image in RGB with needs a image with 0-255 range
img_T1_255 = sitk.Cast(sitk.RescaleIntensity(a), sitk.sitkUInt8)
myshow(sitk.LabelOverlay(img_T1_255, img), "Basic Thresholding")
错误是:

TypeError                                 Traceback (most recent call last)
<ipython-input-70-c44b80227919> in <module>()
      8 img = ((img > 20) * 255).astype(np.uint8)
      9 # To visualize the labels image in RGB with needs a image with 0-255 range
---> 10 img_T1_255 = sitk.Cast(sitk.RescaleIntensity(a), sitk.sitkUInt8)

~/sitkpy/lib/python3.5/site-packages/SimpleITK/SimpleITK.py in RescaleIntensity(image1, outputMinimum, outputMaximum)
  58734 
  58735     """
> 58736     return _SimpleITK.RescaleIntensity(image1, outputMinimum, outputMaximum)
  58737 class RichardsonLucyDeconvolutionImageFilter(ImageFilter_2):
  58738     """

TypeError: in method 'RescaleIntensity', argument 1 of type 'itk::simple::Image const &'

您已将simpletk sitk.Image对象“header”转换为numpy nd.array。此变量名表示未理解sitk.ReadImage返回的内容。SimpleTk筛选器、函数和重载运算符仅适用于sitk.ImageTypes。

否。您需要检查图像。确定多通道的含义,并通过对多通道图像进行阈值化来确定要执行的操作。您可能希望使用sitk.VectorIndexSelectionCast选择一个通道,或者执行类似sitk.vectorignity的操作来组合通道。抱歉,如果我误导了您并告诉您要处理原始像素数据,请始终使用SimpleTik仅用于加载元图像文件,并在此处使用其他LIB(如numpy)处理它们,虽然它有很多自己的处理函数,比如你另一个问题中的重载运算符。你能帮我从305*305*39 nii imageimg=sitk.ReadImageS1.nii中提取切片吗???